Skip to content

Commit

Permalink
backpatch pr#2245 fixes case where duplicate tables are returned if t…
Browse files Browse the repository at this point in the history
…here are duplicate descriptions oids are not guaranteed to be unique in the catalog (#2248)
  • Loading branch information
davecramer committed Sep 9, 2021
1 parent a70834e commit f4928ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1311,9 +1311,7 @@ public ResultSet getTables(@Nullable String catalog, @Nullable String schemaPatt
+ " '' as TYPE_CAT, '' as TYPE_SCHEM, '' as TYPE_NAME, "
+ "'' AS SELF_REFERENCING_COL_NAME, '' AS REF_GENERATION "
+ " FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c "
+ " LEFT JOIN pg_catalog.pg_description d ON (c.oid = d.objoid AND d.objsubid = 0) "
+ " LEFT JOIN pg_catalog.pg_class dc ON (d.classoid=dc.oid AND dc.relname='pg_class') "
+ " LEFT JOIN pg_catalog.pg_namespace dn ON (dn.oid=dc.relnamespace AND dn.nspname='pg_catalog') "
+ " LEFT JOIN pg_catalog.pg_description d ON (c.oid = d.objoid AND d.objsubid = 0 and d.classoid = 'pg_class'::regclass) "
+ " WHERE c.relnamespace = n.oid ";

if (schemaPattern != null && !schemaPattern.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static Iterable<Object[]> data() {

@Before
public void setUp() throws Exception {
Connection conPriv = TestUtil.openPrivilegedDB();
if (binaryMode == BinaryMode.FORCE) {
final Properties props = new Properties();
PGProperty.PREPARE_THRESHOLD.set(props, -1);
Expand All @@ -87,6 +88,13 @@ public void setUp() throws Exception {
TestUtil.createCompositeType(con, "custom", "i int", false);
TestUtil.createCompositeType(con, "_custom", "f float", false);

// create a table and multiple comments on it
TestUtil.createTable(con, "duplicate", "x text");
TestUtil.execute("comment on table duplicate is 'duplicate table'", con);
TestUtil.execute("create or replace function bar() returns integer language sql as $$ select 1 $$", con);
TestUtil.execute("comment on function bar is 'bar function'", con);
TestUtil.execute("update pg_description set objoid = 'duplicate'::regclass where objoid = 'bar'::regproc",conPriv);

// 8.2 does not support arrays of composite types
TestUtil.createTable(con, "customtable", "c1 custom, c2 _custom"
+ (TestUtil.haveMinimumServerVersion(con, ServerVersion.v8_3) ? ", c3 custom[], c4 _custom[]" : ""));
Expand Down Expand Up @@ -125,6 +133,8 @@ public void tearDown() throws Exception {
// metadatatest table's type
Statement stmt = con.createStatement();
stmt.execute("DROP FUNCTION f4(int)");
TestUtil.execute("drop function bar()", con);
TestUtil.dropTable(con, "duplicate");

TestUtil.dropView(con, "viewtest");
TestUtil.dropTable(con, "metadatatest");
Expand Down

0 comments on commit f4928ce

Please sign in to comment.