Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PgDatabaseMetaData.getIndexInfo() cast operands to smallint #2242

Merged
merged 1 commit into from Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2528,14 +2528,14 @@ public ResultSet getIndexInfo(
+ " trim(both '\"' from pg_catalog.pg_get_indexdef(tmp.CI_OID, tmp.ORDINAL_POSITION, false)) AS COLUMN_NAME, "
+ (connection.haveMinimumServerVersion(ServerVersion.v9_6)
? " CASE tmp.AM_NAME "
+ " WHEN 'btree' THEN CASE tmp.I_INDOPTION[tmp.ORDINAL_POSITION - 1] & 1 "
+ " WHEN 'btree' THEN CASE tmp.I_INDOPTION[tmp.ORDINAL_POSITION - 1] & 1::smallint "
+ " WHEN 1 THEN 'D' "
+ " ELSE 'A' "
+ " END "
+ " ELSE NULL "
+ " END AS ASC_OR_DESC, "
: " CASE tmp.AM_CANORDER "
+ " WHEN true THEN CASE tmp.I_INDOPTION[tmp.ORDINAL_POSITION - 1] & 1 "
+ " WHEN true THEN CASE tmp.I_INDOPTION[tmp.ORDINAL_POSITION - 1] & 1::smallint "
+ " WHEN 1 THEN 'D' "
+ " ELSE 'A' "
+ " END "
Expand Down
Expand Up @@ -111,6 +111,12 @@ public void setUp() throws Exception {
"CREATE OR REPLACE FUNCTION f5() RETURNS TABLE (i int) LANGUAGE sql AS 'SELECT 1'");
}

// create a custom `&` operator, which caused failure with `&` usage in getIndexInfo()
stmt.execute(
"CREATE OR REPLACE FUNCTION f6(numeric, integer) returns integer as 'BEGIN return $1::integer & $2;END;' language plpgsql immutable;");
stmt.execute("DROP OPERATOR IF EXISTS & (numeric, integer)");
stmt.execute("CREATE OPERATOR & (LEFTARG = numeric, RIGHTARG = integer, PROCEDURE = f6)");

TestUtil.createDomain(con, "nndom", "int not null");
TestUtil.createDomain(con, "varbit2", "varbit(3)");
TestUtil.createDomain(con, "float83", "numeric(8,3)");
Expand Down Expand Up @@ -143,6 +149,8 @@ public void tearDown() throws Exception {
stmt.execute("DROP FUNCTION f1(int, varchar)");
stmt.execute("DROP FUNCTION f2(int, varchar)");
stmt.execute("DROP FUNCTION f3(int, varchar)");
stmt.execute("DROP OPERATOR IF EXISTS & (numeric, integer)");
stmt.execute("DROP FUNCTION f6(numeric, integer)");
TestUtil.dropTable(con, "domaintable");
TestUtil.dropDomain(con, "nndom");
TestUtil.dropDomain(con, "varbit2");
Expand Down