Skip to content

Fix printing of COPY HEADER with an integer and REJECT_LIMIT - #247

Merged
lelit merged 1 commit into
lelit:v8from
zzoraemon043:fix/copy-header-reject-limit
Nov 25, 2026
Merged

lelit merged 1 commit into
lelit:v8from
zzoraemon043:fix/copy-header-reject-limit

Conversation

@zzoraemon043

Copy link
Copy Markdown
Contributor

Two problems in the CopyStmt DefElem printer:

  • HEADER 0 / HEADER 1 (accepted by PostgreSQL as boolean values) parse with an Integer argument, and the printer crashed reading argv.sval:

    >>> from pglast.stream import RawStream
    >>> RawStream()("COPY t FROM STDIN (FORMAT csv, HEADER 1)")
    AttributeError: 'Integer' object has no attribute 'sval'
    
  • REJECT_LIMIT was written without a space before its value:

    >>> RawStream()("COPY t FROM STDIN (ON_ERROR ignore, REJECT_LIMIT 5)")
    'COPY t FROM STDIN WITH (ON_ERROR ignore, REJECT_LIMIT5)'
    

    That reparses as an option named reject_limit5 without an argument. The value is now printed with print_node(), so a limit that parses as a Float (e.g. 10000000000) works too.

Added the cases to tests/test_printers_roundtrip/dml/copy.sql; they fail without the change. The HEADER part also applies to v7; REJECT_LIMIT is PostgreSQL 18 only.

HEADER 0 and HEADER 1 carry an Integer argument, which the printer
read as a String and crashed on. REJECT_LIMIT was written without a
space, so REJECT_LIMIT 5 came back as an option named reject_limit5.
@lelit
lelit merged commit 4bd2549 into lelit:v8 Nov 25, 2026
10 checks passed
@lelit

lelit commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you. I splitted this into two parts, applying (slightly different) change to v7 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants