Getting syntax error when using the sql operator (pg)
Trying to execute this line of code:
the query that is produced by drizzle:
and getting this error:
No idea why, any insight would be appreciated!
5 Replies
Is this correct pg syntax? Are you attempting to Update a table?
Hi, thanks for the reply! Yes it is. It runs in the db just fine. Also works with sql.raw() but that would introduce a security flaw. This sets a temporary variable in the database and is later accessed using
for row level security
I guess it postgres doesn't support params in that sql statement, has to be hardcoded?
You could do
That would basically bypass sql inyection countermeasures
Great, I'll try that. Thanks for your help!
Following up on this old thread…
Postgres allows setting a setting with the
SET
keyword:
But you can't put SET
in a prepared statement:
Postgres also allows setting a setting with the set_config
function. The third argument is whether the setting is scoped to the transaction (true
) or to the session (false
):
Because it's a function, you can put this in a prepared statement:
Because web applications tend to reuse one Postgres session for many end-users, I recommend passing true
for the third argument. That means you must wrap your work in a transaction. Otherwise, the setting will disappear before your next statement!