-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Hello. I'm using node-postgres. And I want to insert some strings into some table.
If I'm using single query, I can do like this and everything is working ok:
client.query('INSERT INTO sometbl VALUES ($1, $2)', ['foo', 'bar']);
But since I am using transactions and trying to do like this:
client.query('BEGIN; INSERT INTO sometbl VALUES ($1, $2); UPDATE sometable SET somevalue = $3; END;', ['foo', 'bar', 'foobar']);
I am getting an error with code 42601: 'cannot insert multiple commands into a prepared statement'
.
Yes, I know that I can use simple string concatenation or some realizations of sprintf() to insert these parameters into the query string, but, I think, it isn't safe to do it without any preparation like escaping.
Is there some convinient way to do such preparation before inserting string values into the query string?
For example, I have found PQescapeLiteral function in the libpq, maybe there is some interface to this or similar function exists?
If no, can it be implemented?
//Sorry if the question is silly, I'm newbie in postgresql and node.