Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pg_query_go/v4 no longer accepts ? for input placeholders #78

Open
kyleconroy opened this issue Feb 27, 2023 · 2 comments
Open

pg_query_go/v4 no longer accepts ? for input placeholders #78

kyleconroy opened this issue Feb 27, 2023 · 2 comments
Labels

Comments

@kyleconroy
Copy link

kyleconroy commented Feb 27, 2023

In the process of upgrading from v2 to v4 (sqlc-dev/sqlc#2114) I discovered a breaking change. In v2, the following query parses without an error:

SELECT * FROM users WHERE id = ?

However, in v4, this same query now returns a syntax error.

Is this a PostgreSQL change or pg_query_go change?

A full reproduction here: https://gist.github.com/kyleconroy/792b77389287f34a501e572b6c7281df

@lfittl
Copy link
Member

lfittl commented Feb 27, 2023

@kyleconroy This change is intentional - that was always a libpg_query patch, Postgres never supported this syntax for parameter references. Though some ORMs support ? replacement characters, they then do local substitution and don't send the query in that form to the Postgres server.

The motivation for having this modified parser grammar in pg_query to begin with was that we wanted to be able to read the query texts produced by pg_stat_statements, which prior to Postgres 10 used ? (see the commit that changes this for reference).

Since those Postgres versions have reached end of life for over a year now, we decided to drop support for ? replacement characters, which also solves a few edge cases where it caused problems with operators containing ? (see e.g. pganalyze/libpg_query#132)

It sounds like this might be a problem for sqlc. Can you describe a bit more the use case for using ?? (are you doing local substitution of the values before sending them to Postgres?)

@kyleconroy
Copy link
Author

Postgres never supported this syntax for parameter references

Okay, that's great news. sqlc does not do the parameter re-writing, so this shouldn't be a breaking change for users. While the parser allowed those placeholders, those queries never would have worked in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants