V
V
veryoriginalnickname2021-10-10 01:10:04
go
veryoriginalnickname, 2021-10-10 01:10:04

Why placeholder parameters don't work everywhere?

I did not really understand which tag this question should be attributed to, either to postgres or go. Why doesn't this work?
SELECT * FROM chtoto WHERE $1=$2 LIMIT 1
but this works
SELECT * FROM chtoto WHERE id=$1 LIMIT 1
with order by even sadder, you have to do this:

fmt.Sprintf("SELECT * FROM chtoto WHERE id >= $1 ORDER BY %v %v, id %v LIMIT $2 + 1", one, two, two)

Might be a dumb question, I couldn't find anything on Google.

upd: I understand that the output is something like this:
SELECT * FROM chtoto WHERE 'id'='513135513315' LIMIT 1

and because id is in quotes, nothing works?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Demin, 2021-10-10
@veryoriginalnickname

Because instead of $1, $2, etc. values ​​should be substituted, not column names

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question