Skip to content

Add support for INTERVAL keyword as unquoted identifier in PostgreSQL#2238

Merged
yoavcloud merged 1 commit intoapache:mainfrom
LucaCappelletti94:pg_query_parity_3
Feb 25, 2026
Merged

Add support for INTERVAL keyword as unquoted identifier in PostgreSQL#2238
yoavcloud merged 1 commit intoapache:mainfrom
LucaCappelletti94:pg_query_parity_3

Conversation

@LucaCappelletti94
Copy link
Contributor

This PR fixes a PostgreSQL dialect parsing bug where INTERVAL was always treated as a reserved identifier keyword, causing valid queries such as:

SELECT MAX(interval) FROM tbl

to fail with Expected: an expression, found: ).

Problem

In PostgreSQL, interval can be used as an unquoted identifier in unambiguous expression positions (for example function arguments). Our parser attempted INTERVAL-literal parsing first, and on failure it only fell back to identifier parsing when the keyword is not reserved. Because INTERVAL was reserved for PostgreSqlDialect, fallback was blocked.

Fix

  • Added a PostgreSQL-specific override of is_reserved_for_identifier so Keyword::INTERVAL is not treated as reserved in this dialect.
  • Kept default reserved behavior for all other keywords unchanged.

Tests

Added regression test in PostgreSQL-specific suite:

  • SELECT MAX(interval) FROM tbl now parses successfully in PostgreSqlDialect.
  • INTERVAL '1 day' still parses as an interval expression (guarding against regressions).

Impact

  • Improves compatibility with real-world PostgreSQL schemas where columns/args may be named interval.
  • No public API changes.
  • No cross-dialect behavior changes intended beyond PostgreSQL’s INTERVAL identifier handling.

@LucaCappelletti94 LucaCappelletti94 marked this pull request as ready for review February 25, 2026 10:54
@yoavcloud yoavcloud added this pull request to the merge queue Feb 25, 2026
Merged via the queue into apache:main with commit 982068e Feb 25, 2026
10 checks passed
LucaCappelletti94 added a commit to LucaCappelletti94/sqlparser-rs that referenced this pull request Feb 27, 2026
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