Skip to content

DuckDB reserved keywords used as column/field names cause parse errors in pushed-down queries #277

@sfc-gh-okalaci

Description

@sfc-gh-okalaci

I realized while reviewing #274, but seems a lot more common than that.

CREATE TABLE t_pivot_bug (pivot int, b text) USING iceberg;
CREATE TABLE
Time: 21.265 ms
postgres=# INSERT INTO t_pivot_bug VALUES (1, 'hello');
ERROR:  Parser Error: syntax error at or near "pivot"

LINE 1: COPY (SELECT pivot, b FROM read_csv('/Users/okalaci/pg-install/data_pg17...
                     ^

LINE 1: COPY (SELECT pivot, b FROM read_csv('/Users/okalaci/pg-install/data_pg17...
                     ^
Time: 8.201 ms

quote_identifier() uses PostgreSQL's keyword list to decide whether to double-quote identifiers in SQL sent to DuckDB (pgduck_server). Identifiers that are DuckDB RESERVED_KEYWORD but not PostgreSQL keywords pass through unquoted, causing DuckDB parse errors.

This affects:

  1. Column names in any pushed-down SELECT or INSERT...SELECT (deparse layer in deparse.c)
  2. Composite field names in the temporal validation struct_pack generation (iceberg_query_validation.c)

Affected keywords

DuckDB RESERVED_KEYWORD tokens that are not PostgreSQL keywords (and thus never quoted by quote_identifier()):

Keyword DuckDB category PostgreSQL status
describe RESERVED not a keyword
lambda RESERVED not a keyword
pivot RESERVED not a keyword
pivot_longer RESERVED not a keyword
pivot_wider RESERVED not a keyword
qualify RESERVED not a keyword
summarize RESERVED not a keyword
unpivot RESERVED not a keyword
show RESERVED unreserved (not quoted)

Source: duckdb_pglake/duckdb/third_party/libpg_query/include/parser/kwlist.hpp

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions