Skip site navigation (1) Skip section navigation (2)

Is this legal SQL? Is it a good practice?

From: Carlos Moreno <moreno(at)mochima(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Is this legal SQL? Is it a good practice?
Date: 2004-08-24 20:52:23
Message-ID: 412BAA87.50808@mochima.com (view raw or flat)
Thread:
Lists: pgsql-general
I just noticed that from a C or C++ program using
libpq or libpq++, I can send *one* command that
contains several SQL statements separated by
semicolon.  Something like:

PgDatabase db (" .... ");

const char * const sql =
     "insert into blah (...); insert into blah (...)";

if (db.Exec (sql) == PGRES_COMMAND_OK)
{
     cout << "Fine!" << endl;
}

And I verify the table, and all the inserts took place
(and of course, the program outputs "Fine!").

But I'm wondering -- is this a PostgreSQL extension,
or is it "legal SQL"?  In particular, I'm wondering
if it is a feature that in the future you might
decide to eliminate for not being ANSI-SQL compliant.

What happens if the first command is ok but the second
one fails?  I guess PgDatabase::Exec would return an
error code, and PgDatabase::ErrorMessage would return
the error message corresponding to the second statement
(the one that failed).  Am I correct in thinking this?

Any reason why this should be avoided?  (on the plus
side, I think this might increase efficiency for
transactions where one executes several insert or
update statements).

Thanks for any comments,

Carlos
--


Responses

pgsql-general by date

Next:From: Tom LaneDate: 2004-08-24 21:07:06
Subject: Re: Problem to connect to the Windows Port
Previous:From: Carlos MorenoDate: 2004-08-24 20:41:23
Subject: How is this possible? (more on deadlocks)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group