Skip to content

Commit

Permalink
Revert "feat: add way to distinguish base and partitioned tables in P…
Browse files Browse the repository at this point in the history
…gDatabaseMetaData.getTables (pgjdbc#1708)"

This reverts commit 25eb32c
  • Loading branch information
mdespriee committed Jul 29, 2021
1 parent 207ce36 commit c393bb7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
11 changes: 4 additions & 7 deletions pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java
Expand Up @@ -1298,7 +1298,7 @@ public ResultSet getTables(@Nullable String catalog, @Nullable String schemaPatt
+ " END "
+ " WHEN false THEN CASE c.relkind "
+ " WHEN 'r' THEN 'TABLE' "
+ " WHEN 'p' THEN 'PARTITIONED TABLE' "
+ " WHEN 'p' THEN 'TABLE' "
+ " WHEN 'i' THEN 'INDEX' "
+ " WHEN 'S' THEN 'SEQUENCE' "
+ " WHEN 'v' THEN 'VIEW' "
Expand Down Expand Up @@ -1353,12 +1353,9 @@ public ResultSet getTables(@Nullable String catalog, @Nullable String schemaPatt
tableTypeClauses = new HashMap<String, Map<String, String>>();
Map<String, String> ht = new HashMap<String, String>();
tableTypeClauses.put("TABLE", ht);
ht.put("SCHEMAS", "c.relkind = 'r' AND n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'");
ht.put("NOSCHEMAS", "c.relkind = 'r' AND c.relname !~ '^pg_'");
ht = new HashMap<String, String>();
tableTypeClauses.put("PARTITIONED TABLE", ht);
ht.put("SCHEMAS", "c.relkind = 'p' AND n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'");
ht.put("NOSCHEMAS", "c.relkind = 'p' AND c.relname !~ '^pg_'");
ht.put("SCHEMAS",
"c.relkind IN ('r','p') AND n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'");
ht.put("NOSCHEMAS", "c.relkind IN ('r','p') AND c.relname !~ '^pg_'");
ht = new HashMap<String, String>();
tableTypeClauses.put("VIEW", ht);
ht.put("SCHEMAS",
Expand Down
Expand Up @@ -34,7 +34,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
Expand Down Expand Up @@ -810,27 +809,11 @@ public void testPartialIndexInfo() throws SQLException {

@Test
public void testTableTypes() throws SQLException {
final List<String> expectedTableTypes = new ArrayList<String>(Arrays.asList("FOREIGN TABLE", "INDEX",
"MATERIALIZED VIEW", "PARTITIONED TABLE", "SEQUENCE", "SYSTEM INDEX", "SYSTEM TABLE", "SYSTEM TOAST INDEX",
"SYSTEM TOAST TABLE", "SYSTEM VIEW", "TABLE", "TEMPORARY INDEX", "TEMPORARY SEQUENCE", "TEMPORARY TABLE",
"TEMPORARY VIEW", "TYPE", "VIEW"));
final List<String> foundTableTypes = new ArrayList<String>();

// Test that no exceptions are thrown
// At the moment just test that no exceptions are thrown KJ
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);

// Test that the table types returned are the same as those expected
ResultSet rs = dbmd.getTableTypes();
while (rs.next()) {
String tableType = new String(rs.getBytes(1));
foundTableTypes.add(tableType);
}
rs.close();
Collections.sort(expectedTableTypes);
Collections.sort(foundTableTypes);
Assert.assertEquals("The table types received from DatabaseMetaData should match the 17 expected types",
true, foundTableTypes.equals(expectedTableTypes));
}

@Test
Expand Down Expand Up @@ -1338,7 +1321,7 @@ public void testPartitionedTables() throws SQLException {
stmt.execute(
"CREATE TABLE measurement (logdate date not null,peaktemp int,unitsales int ) PARTITION BY RANGE (logdate);");
DatabaseMetaData dbmd = con.getMetaData();
ResultSet rs = dbmd.getTables("", "", "measurement", new String[]{"PARTITIONED TABLE"});
ResultSet rs = dbmd.getTables("", "", "measurement", new String[]{"TABLE"});
assertTrue(rs.next());
assertEquals("measurement", rs.getString("table_name"));

Expand Down

0 comments on commit c393bb7

Please sign in to comment.