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

pg_query.proto: Add Token ASCII_36; Add scan test #211

Closed evanj closed 1 year ago

evanj commented 1 year ago

Postgres's scanner will scan $ into a single token. For example:

    SELECT $identifier;

The parser will later reject this. However, since the scanner returns this value, we should define a Token for it in the protobuf.

test/scan.c:

evanj commented 1 year ago

As far as I know so far: this $ token is always a parse error. According to my reading of the documentation, Postgres does not permit $ as an operator, but it does permit it:

I found this because I wrote a fuzz test for a tool that is rewriting Postgres queries using https://github.com/pganalyze/pg_query_go , and it happened to generate this. The "unsupported" token caused my fuzz test to be unhappy.

So: This isn't "needed", except for completeness for supporting any Postgres tool.