Postgres Error Cannot Insert Multiple Commands Into A Prepared Statement
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business cannot insert multiple commands into a prepared statement postgresql Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
Node Postgres Cannot Insert Multiple Commands Into A Prepared Statement
Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just
Vertica Cannot Insert Multiple Commands Into A Prepared Statement
like you, helping each other. Join them; it only takes a minute: Sign up Error “cannot insert multiple commands into a prepared statement” up vote 2 down vote favorite Using PHP 5.3.3, PostgreSQL 8.4.11, pgbouncer 1.3.4 (in
Golang Cannot Insert Multiple Commands Into A Prepared Statement
session mode) on CentOS 6.2 I'm trying to execute several SQL commands and fetch the results by a PHP script. When I copy the commands from script to psql prompt they work flawlessly and return 12 rows: But when I run from script I get the error: SQLSTATE[42601]: Syntax error: 7 ERROR: cannot insert multiple commands into a prepared statement Any help please? Below is my failing PHP code, I tried using $db->query() instead of redshift cannot insert multiple commands into a prepared statement $db->prepare/execute too: try { $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); $db = new PDO(sprintf('pgsql:host=%s port=%u; dbname=%s', DBHOST, DBPORT, DBNAME), DBUSER, DBPASS, $options); $sth = $db->prepare(" start transaction; create temporary table temp_ids (id varchar not null) on commit drop; insert into temp_ids (id) select id from pref_money where yw = to_char(current_timestamp - interval '1 week', 'IYYY-IW') order by money desc limit 10; create temporary table temp_rids (rid integer not null) on commit drop; insert into temp_rids (rid) select rid from pref_cards where stamp > now() - interval '1 day' and id in (select id from temp_ids) and bid = 'Мизер' and trix > 0; SELECT r.rid, r.cards, to_char(r.stamp, 'DD.MM.YYYY HH24:MI') as day, c.bid, c.trix, c.pos, c.money, c.last_ip, c.quit, u.id, u.first_name, u.avatar, u.female, u.city, u.vip > CURRENT_DATE as vip FROM pref_rounds r, pref_cards c, pref_users u WHERE u.id = c.id and r.rid = c.rid and r.rid in (select rid from temp_rids) order by rid, pos; commit; "); $sth->execute(); while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { # stuff a JSON object } } catch (Exception $e) { exit('Database problem: ' . $e->getMessage()); } php postgresql pdo postgresql-8.4 share|improve this question edited Jun 13 '12 at 10:47 hakre 134k26216390 asked Jun 13 '12 at 8:18 Alexander Farber 4,51738139275 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote Try this, begin a transaction and s
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us cannot insert multiple commands into a prepared statement rails Learn more about Stack Overflow the company Business Learn more about hiring developers or cannot insert multiple commands into a prepared statement node posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow cannot insert multiple commands into a prepared statement nodejs Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Inserting multiple commands into prepared statement rails up vote http://stackoverflow.com/questions/11010784/error-cannot-insert-multiple-commands-into-a-prepared-statement 0 down vote favorite I am using rails 3 and I need to execute raw sql in one of my migration and I need to do it using prepared statement since it is the best way to escape problems which arise due to single, statement or so. Is there a way where in I can execute multiple sql statements in a single prepare statement. I am using http://stackoverflow.com/questions/33014119/inserting-multiple-commands-into-prepared-statement-rails PostgreSQL for my database Here is my code what i tried CONN = ActiveRecord::Base.connection.raw_connection sql = %Q[ INSERT INTO table1 ( name, email, phone, created_at, updated_at ) VALUES ( $1, $2, $3, current_timestamp, current_timestamp ); UPDATE table2 SET column_1 = $1 WHERE id = $4; UPDATE contacts SET column_2 = $2 WHERE id = $4 ] CONN.prepare('insert_and_update', sql) CONN.exe_prepared('insert_and_update', [ name, email, phone, customer.id ]) But I am getting error as cannot insert multiple commands into a prepared statement ruby-on-rails-3 postgresql prepared-statement execute prepare share|improve this question edited Oct 20 '15 at 10:12 asked Oct 8 '15 at 11:11 Ankita.P 120213 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted Turn it into a single command: with i as ( insert into table1 ( name, email, phone, created_at, updated_at ) values ( $1, $2, $3, current_timestamp, current_timestamp ), u as ( update table2 set column_1 = $1 where id = $4 ) update contacts set column_2 = $2 where id = $4 ; share|improve this answer answered Oct 8 '15 at 11:35 Clodoaldo Neto 48.1k869117 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google
pgsql-announce pgsql-bugs pgsql-docs pgsql-general pgsql-interfaces pgsql-jobs pgsql-novice pgsql-performance pgsql-php pgsql-sql pgsql-students Developer lists Regional https://www.postgresql.org/message-id/CAADeyWh+JUOFRxVTO7OQMRav7L_bq1BZvBVfdch9=+7-ik1TPw@mail.gmail.com lists Associations User groups Project lists Inactive lists IRC https://codedump.io/share/eguZLj69ijC5/1/execute-multiple-queries-in-a-single-statement-using-postgres-and-node-js Local User Groups Featured Users International Sites Propaganda Resources Weekly News Trying to execute several queries involving temp tables in a PHP script From: Alexander Farber
Go Groovy Haml Handlebars Haskell HTML HTTP Ini iOS Jade Java Javascript jQuery JSON Julia Keyman LaTeX Linux Less LOLCODE Makefile Markdown MATLAB MySQL NASM Node.js NSIS Objective-C Pascal Perl PHP PHP Extras PowerShell Python R React JSX reST (reStructuredText) Rip Ruby Rust SAS Sass (Sass) Sass (Scss) Scala Scheme Smalltalk Smarty SQL Stylus Swift Twig TypeScript Vb.net VHDL Wiki markup YAML Other Search Abdul Manaf - 7 months ago 520x SQL Question Execute multiple queries in a single statement using postgres and node js I need to execute insert and delete query in a single statement like this INSERT INTO COMPANY (ID,NAME) VALUES (1, 'Paul');DELETE FROM COMPANY WHERE ID='12';
This is my node.js code for executing query pg.connect(pgConString, function (err, client, done) {
if (err) {
callBack("DB connection failed. " + err, null);
return;
}
var query = client.query({
text: "INSERT INTO COMPANY (ID,NAME) VALUES (1, 'Paul');DELETE FROM COMPANY WHERE ID='12';"
values: [1, "Poul1"],
name: "insertQuery"
});
query.on("error", function (err) {
callBack("DB insertion failed. Error Message: " + err, null);
return;
});
query.on('end', function (result) {
done();
return;
});
});
I got error message like this error: cannot insert multiple commands into a prepared statement is it possible to execute multiple queries in postgresql database using node.js ? anas p a Answer Email {} Share Try like this pg.connect(pgConString, function (err, client, done) { if (err) { callBack("DB connection failed. " + err, null); return; } client.query({ text: "INSERT INTO COMPANY (ID,NAME) VALUES (1, 'Paul');", values: [1, "Poul1"], name: "insertQuery" }); client.query({ text: "DELETE FROM COMPANY WHERE ID='12';", name: "deleteQuery" }); client.on("error", function (err) { callBack("DB insertion failed. Error Message: " + err, null); return; }); }); Source (Stackoverflow) http://stackoverflow.com/questions/35625360/execute-multiple-queries-in-a-single-statement-using-postgres-and-node-js Comments Please enable JavaScript to view the comments powered by Disqus. × Email codedump link for Execute multiple queries in a single statement using postgres and node js Email has been send. To emailaddress: To name: From name: Extra information in the email body (optional): Email: I am sending you the codedump of Execute multiple queries i