pganalyze / libpg_query

C library for accessing the PostgreSQL parser outside of the server environment
BSD 3-Clause "New" or "Revised" License
1.21k stars 182 forks source link

Allow trailing junk in numeric literals #177

Closed msepga closed 1 year ago

msepga commented 1 year ago

This reverts PSQL commit 2549f066, a grammar change which rejects trailing text on numeric literals. The original patch was intended to support future numeric literal syntax, however the changes did not need to be so aggressive. For now this is reverted, until a more relaxed grammar is implemented, with the upcoming PG16 release in mind.

lfittl commented 1 year ago

For additional context on anyone else looking at this PR in the future: The main problem that libpg_query users have with this upstream change (and that we've seen in the pganalyze app), is that pg_stat_statements can produce output like "SELECT * FROM x WHERE y=$1ORz=$2" (note the missing space between $1 and OR), which is rejected by the Postgres 15 parser.

The upstream change here was mainly intended to allow for 0x123def and 100_000_000 syntax changes in Postgres 16, and didn't really intentionally change the parameter reference handling, from what I can gather. For Postgres 16 we'll try to make a more surgical change that only keeps the old behavior (allowing trailing "junk") for parameter references, whilst supporting the new syntax - but for PG15 reverting that preparatory commit (as done here), is the easier change.