pg_duckdb icon indicating copy to clipboard operation
pg_duckdb copied to clipboard

add duckdb.describe('foobar') -> DESCRIBE foobar

Open wuputah opened this issue 5 months ago • 0 comments

The shape of the result of a DESCRIBE call is constant, so hopefully we can avoid the AS ... syntax for this function.

Some example usage in DuckDB:

D create table foo (bar int, baz text);
D describe foo;
┌─────────────┬─────────────┬─────────┬─────────┬─────────┬─────────┐
│ column_name │ column_type │  null   │   key   │ default │  extra  │
│   varchar   │   varchar   │ varchar │ varchar │ varchar │ varchar │
├─────────────┼─────────────┼─────────┼─────────┼─────────┼─────────┤
│ bar         │ INTEGER     │ YES     │         │         │         │
│ baz         │ VARCHAR     │ YES     │         │         │         │
└─────────────┴─────────────┴─────────┴─────────┴─────────┴─────────┘
D describe select 1, 2, 3, * from foo;
┌─────────────┬─────────────┬─────────┬─────────┬─────────┬─────────┐
│ column_name │ column_type │  null   │   key   │ default │  extra  │
│   varchar   │   varchar   │ varchar │ varchar │ varchar │ varchar │
├─────────────┼─────────────┼─────────┼─────────┼─────────┼─────────┤
│ 1           │ INTEGER     │ YES     │         │         │         │
│ 2           │ INTEGER     │ YES     │         │         │         │
│ 3           │ INTEGER     │ YES     │         │         │         │
│ bar         │ INTEGER     │ YES     │         │         │         │
│ baz         │ VARCHAR     │ YES     │         │         │         │
└─────────────┴─────────────┴─────────┴─────────┴─────────┴─────────┘

There is additional usage with httpfs that would handy to support as well, but the syntax adds the keyword table and then the filename is quoted. Perhaps this should be a parameter like remote => true that indicates the parameter is a remote file. https://duckdb.org/docs/guides/meta/describe.html#describing-remote-tables

This syntax does not work without adding the table keyword.

D describe 'https://datasets.clickhouse.com/hits_compatible/hits.parquet';
Parser Error: syntax error at or near "'https://datasets.clickhouse.com/hits_compatible/hits.parquet'"
LINE 1: describe 'https://datasets.clickhouse.com/hits_c...
                 ^

wuputah avatar Sep 05 '24 20:09 wuputah