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

How to identify the partitioned tables in getTables? #1590

Closed
1 of 2 tasks
buremba opened this issue Oct 24, 2019 · 8 comments · Fixed by #1708
Closed
1 of 2 tasks

How to identify the partitioned tables in getTables? #1590

buremba opened this issue Oct 24, 2019 · 8 comments · Fixed by #1708
Assignees

Comments

@buremba
Copy link

buremba commented Oct 24, 2019

We're using the PgDatabaseMetadata in order to list the tables in a given schema but since we're extensively using partitioned tables, it returns hundreds of tables. However; we only need the BASE table and discard the PARTITIONED tables under the BASE table but couldn't find any info about the relkind in PgDatabaseMetadata.

  • bug report
  • feature request

Describe the issue
A clear and concise description of what the issue is.

Driver Version?
42.2.6

Java Version?
8

PostgreSQL Version?
12

Expected behavior
Ideally, we should either expose relkind in PgDatabaseMetadata or provide a way for the developer to identify the partitioned tables.

@davecramer
Copy link
Member

Seems like something that would be useful. Are you up to providing a PR ?

@buremba
Copy link
Author

buremba commented Oct 24, 2019

@davecramer Which approach do you prefer, exposing relkind in ResultSet or something like is_partitioned?

@davecramer
Copy link
Member

I think I'd like to see relkind and then have it return an enum of the different kinds.

@jorsol
Copy link
Member

jorsol commented Oct 24, 2019

I would not said "expose" relkind, but extend current tableTypeClauses so the TABLE_TYPE of getTables shows PARTITIONED TABLE.

@davecramer davecramer self-assigned this Nov 28, 2019
MSGoodman added a commit to MSGoodman/pgjdbc that referenced this issue Feb 18, 2020
…eMetaData.getTables

There is currently no way to distinguish between base tables and
partitioned tables in the response from PgDatabadeMetaData.getTables.
Fix this by adding PARTITIONED TABLE to the tableTypeClauses map and
thus the TABLE_TYPE field in the query in getTables. Also update a test
(testPartitionedTables) that was using TABLE_TYPE of TABLE to grab
partitioned tables.

This should close pgjdbc#1590. However, perhaps this could be considered a
breaking change for anyone using getTables and expecting partitioned
tables to show up for .getTables(s, s1, s2, new String[]{"TABLE"})?
davecramer pushed a commit that referenced this issue Feb 25, 2020
…eMetaData.getTables (#1708)

* feat: add way to distinguish base and partitioned tables in PgDatabaseMetaData.getTables

There is currently no way to distinguish between base tables and
partitioned tables in the response from PgDatabadeMetaData.getTables.
Fix this by adding PARTITIONED TABLE to the tableTypeClauses map and
thus the TABLE_TYPE field in the query in getTables. Also update a test
(testPartitionedTables) that was using TABLE_TYPE of TABLE to grab
partitioned tables.

This should close #1590. However, perhaps this could be considered a
breaking change for anyone using getTables and expecting partitioned
tables to show up for .getTables(s, s1, s2, new String[]{"TABLE"})?

* test: improve database metadata table type test
@buremba
Copy link
Author

buremba commented Feb 25, 2020

Thanks!

@gbhat618
Copy link

Hi All,
I want to ask how to list all the root tables (base tables in case of partition tables + regular tables) using the jdbc driver?

In the feature implemented 1708, we can do getTables for PARTITIONED TABLE, which returns the list of base tables which are partitioned. It returns the tables that are created by syntax like,

CREATE TABLE t (
...
) PARTITION BY RANGE (col_name);

While to get the regular tables we need to use getTables for TABLE, which returns regular tables, but also returns the partitions of the base table as well.

But I want to get --> regular tables (non-partitions) + base tables.

In the output of getTables, seems no way to find whether it is a partition or not, as the available columns are only,

table_cat
table_schem
table_name
table_type
remarks
type_cat
type_schem
type_name
self_referencing_col_name
ref_generation

So it is not possible to get regular tables (but not paritions) using JDBC metadata apis alone right?
Probably need to make an SQL query to the db and do some filtering in the getTables output.

It seems from the postgres documentation, pg_class column relispartition is the one to determine.
References

  1. PG Doc: pg_class
  2. SO: Show only list of tables without child partitions
  3. SO: How to list all tables in postgres without partitions

@davecramer
Copy link
Member

There is no JDBC API that provides this information as far as I know so as you surmised you would have to query pg_class on your own

@gbhat618
Copy link

ok, thank you so much for the confirming, also thanks for the quick reply 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants