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

fix: make sure we select array_in from pg_catalog to avoid duplicate array_in functions fixes Issue #2548 #2552

Merged
merged 4 commits into from Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -219,7 +219,7 @@ private String getSQLTypeQuery(boolean typoidParam) {
// (keeping old behaviour of finding types, that should not be found without correct search
// path)
StringBuilder sql = new StringBuilder();
sql.append("SELECT typinput='array_in'::regproc as is_array, typtype, typname, pg_type.oid ");
sql.append("SELECT typinput='pg_catalog.array_in'::regproc as is_array, typtype, typname, pg_type.oid ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davecramer , do you know if pg_type.typarray != 0 answers that better?
typarray was added in 8.3: https://www.postgresql.org/docs/8.3/catalog-pg-type.html while we support 8.4+

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If typarray is not 0 then it identifies another row in pg_type, which is the "true" array type having this type as element. So it only says that there is an array type for this type.

Copy link
Member

@vlsi vlsi Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed.

Then PG 14 might bring new joy with its typsubscript and typelem (https://www.postgresql.org/docs/14/catalog-pg-type.html).
However, it looks like typelem has a broader meaning than just an array.

sql.append(" FROM pg_catalog.pg_type ");
sql.append(" LEFT JOIN (select ns.oid as nspoid, ns.nspname, r.r ");
sql.append(" from pg_namespace as ns ");
Expand Down
Expand Up @@ -473,4 +473,25 @@ public void testSortedDataTypes() throws SQLException {
lastType = type;
}
}

@Test
public void testGetSqlTypes() throws SQLException {
if (TestUtil.haveMinimumServerVersion(conn, ServerVersion.v10)) {
try (Connection privileged = TestUtil.openPrivilegedDB()) {
try (Statement stmt = privileged.createStatement()) {
// create a function called array_in
stmt.execute("CREATE OR REPLACE FUNCTION public.array_in(anyarray, oid, integer)\n"
+ " RETURNS anyarray\n"
+ " LANGUAGE internal\n"
+ " STABLE PARALLEL SAFE STRICT\n"
+ "AS $function$array_in$function$");
}
DatabaseMetaData dbmd = privileged.getMetaData();
ResultSet rs = dbmd.getTypeInfo();
try (Statement stmt = privileged.createStatement()) {
stmt.execute("drop function public.array_in(anyarray, oid, integer)");
}
}
}
}
}