Multi prepared statements
Hi,
I would like to create a transaction with multiple inserts (prepared statements) but it seems to be impossible, despite the fact @robconery suggests it is super easy in #163 (closed).
Multi-statement parameterized queries are currently not supported by postgres.
(https://github.com/brianc/node-postgres/wiki/Prepared-Statements#parameterized-queries)
The only way I founded was to create a function instead of a db file.
DB File :
BEGIN;
PREPARE myTest(TEXT, TEXT) AS
INSERT INTO myTable (column1) values ($1), ($2);
END;
=> ERROR: cannot insert multiple commands into a prepared statement
Function :
BEGIN;
CREATE OR REPLACE FUNCTION myFunctionTest(
value1 TEXT,
value2 TEXT
)
RETURNS void AS $$
BEGIN;
PREPARE myTest(TEXT, TEXT) AS
INSERT INTO myTable (column1) values ($1), ($2);
END;
$$ language 'plpgsql';
END;
Do you know any tips to do it with a db file ?
Thanks.