cwida / duckpgq-extension

DuckDB extension that adds support for SQL/PGQ
https://duckpgq.notion.site/b8ac652667964f958bfada1c3e53f1bb?v=3b47a8d44bdf4e0c8b503bf23f1b76f2
MIT License
69 stars 7 forks source link

Parser Error when selecting from `information_schema` views #96

Closed dbeatty10 closed 7 months ago

dbeatty10 commented 8 months ago

What happens?

Selecting from views in the information_schema gives the following error:

Error: Parser Error: syntax error at or near "source"

But I expected either of these to work:

select * from information_schema.tables;
select * from information_schema.columns;

To Reproduce

$ ./build/release/duckdb
D select * from information_schema.tables;

Output:

Error: Parser Error: syntax error at or near "source"

Opening the same file with duckdb and re-running those queries works fine:

$ duckdb db.db

D select * from information_schema.tables;
D select * from information_schema.columns;

Environment

OS: macOS Version: duckdb-pgq v0.10.0 3e6d77b923

After following these installation instructions, here is my current version:

$ ./build/release/duckdb --version

v0.10.0 3e6d77b923
Dtenwolde commented 8 months ago

Thanks for the bug report. It seems to happen because select * from information_schema.tables; calls[1] which contains name_extract['source']. It seems that 'source' is not allowed in a struct or map, but I'll investigate further :)

[1]

SELECT
  f.database_name AS constraint_catalog,
  f.schema_name AS constraint_schema,
  CONCAT(f.source, '_', f.target, '_', f.target_column, '_fkey') AS constraint_name,
  current_database() AS unique_constraint_catalog,
  c.schema_name AS unique_constraint_schema,
  CONCAT(c.table_name, '_', f.target_column, '_',
        CASE WHEN c.constraint_type = 'UNIQUE' THEN 'key' ELSE 'pkey' END) AS unique_constraint_name,
  'NONE' AS match_option,
  'NO ACTION' AS update_rule,
  'NO ACTION' AS delete_rule
FROM duckdb_constraints() c
JOIN (
  SELECT
    *,
    name_extract['source'] AS source,
    name_extract['target'] AS target,
    name_extract['target_column'] AS target_column
  FROM (
    SELECT
      *,
      regexp_extract(constraint_text, 'FOREIGN KEY \\(([a-zA-Z_0-9]+)\\) REFERENCES ([a-zA-Z_0-9]+)\\(([a-zA-Z_0-9]+)\\)', ['source', 'target', 'target_column']) AS name_extract
    FROM duckdb_constraints()
    WHERE constraint_type = 'FOREIGN KEY'
  ) f
) ON name_extract['target'] = c.table_name
AND (c.constraint_type = 'UNIQUE' OR c.constraint_type = 'PRIMARY KEY');