1

I like how duckdb lets me query DataFrames as if they were sql tables:

df = pandas.read_parquet("my_data.parquet")
con.query("select * from df limit 10").fetch_df()

I also like how duckdb has metadata commands like SHOW TABLES;, like a real database. However, SHOW TABLES; doesn't show pandas DataFrames or other table-like objects.

my question is: does duckdb offer something like SHOW TABLES; that includes both (1) real database tables and (2) table-like objects (e.g. pandas DataFrames) and their schemas?

Thanks!

william_grisaitis
  • 5,170
  • 3
  • 33
  • 40
  • 1
    Last time I checked - you would need to register a view and then query `information_schema.columns` https://github.com/duckdb/duckdb/discussions/3623 – jqurious Mar 14 '23 at 01:43

1 Answers1

2

You can use the different metadata table functions duckdb_% as referred here

For an equivalent of SHOW TABLES and convert it as a pandas dataframe

import duckdb

df = duckdb.sql("SELECT * FROM duckdb_tables;").df()
print(df.dtypes)

database_name             object
database_oid               int64
schema_name               object
schema_oid                 int64
table_name                object
table_oid                  int64
internal                    bool
temporary                   bool
has_primary_key             bool
estimated_size             int64
column_count               int64
index_count                int64
check_constraint_count     int64
sql                       object
dtype: object

Note : I'm using the latest version of duckDB v0.7.1

mehdio
  • 291
  • 2
  • 6