Skip to content

Add support for parsing COPY statements from STDIN without a semicolon#2245

Open
LucaCappelletti94 wants to merge 1 commit intoapache:mainfrom
LucaCappelletti94:postgres-regression-1
Open

Add support for parsing COPY statements from STDIN without a semicolon#2245
LucaCappelletti94 wants to merge 1 commit intoapache:mainfrom
LucaCappelletti94:postgres-regression-1

Conversation

@LucaCappelletti94
Copy link
Contributor

This PR fixes PostgreSQL COPY ... FROM STDIN parsing when the statement ends at EOF without a trailing semicolon.

This is one of several failure families I have found in the course of the correctness benchmarks I am running based on resources such as the PostgreSQL regression SQL suite.

Before this change, sqlparser rejected valid inputs such as:

COPY bitwise_test FROM STDIN NULL 'null'

with:

ParserError("Expected: ;, found: EOF")

Root Cause

parse_copy unconditionally required ; for CopyTarget::Stdin before reading optional inline payload rows.

Fix

For COPY ... FROM STDIN:

  • accept immediate EOF as a valid terminator when no inline payload is present
  • keep existing behavior for semicolon + payload parsing unchanged

Tests

Added/updated PostgreSQL regression coverage:

  • parse_copy_from_stdin_without_semicolon
  • parse_copy_from_stdin_without_semicolon_variants

The variants cover multiple FROM stdin shapes without trailing semicolon (columns, legacy options, mixed casing), and assert they parse as Statement::Copy with target: Stdin and empty payload.

@LucaCappelletti94 LucaCappelletti94 marked this pull request as ready for review February 26, 2026 17:30
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.

1 participant