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

pq: syntax error at or near "$2" #977

Open
aditya1808 opened this issue Jun 11, 2020 · 1 comment
Open

pq: syntax error at or near "$2" #977

aditya1808 opened this issue Jun 11, 2020 · 1 comment

Comments

@aditya1808
Copy link

im executing a where query using gromdb
db = db.Where("parameters ? = ?", key, values[0])
key - string, values[0] -> string, parameters is json type
example of key: "->key1"
the whole query may look like this select * from table where parameters ->>key1 = value

But im getting this error
pq: syntax error at or near "$2" although i didnt specify any $2 in my query. Does it internally modify '?' to $x placeholders?

I tried with different placeholder
db = db.Where("parameters $1 = $2", key, values[0])
Then i'm getting pq: syntax error at or near "$1"

could someone help me understand what exactly im doing wrong.

@cbandy
Copy link
Contributor

cbandy commented Jun 11, 2020

pq: syntax error at or near "$2"

That is the shape of PostgreSQL query parameters, yes. Those parameters can only take the place of SQL literals (strings or numbers). They cannot replace SQL operators, identifiers, etc.

Does it internally modify '?' to $x placeholders?

lib/pq doesn't know or do anything with ?, so you should probably seek advice from the package that provides db.Where().

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

No branches or pull requests

2 participants