Is this legal SQL? Is it a good practice? - Mailing list pgsql-general

From Carlos Moreno
Subject Is this legal SQL? Is it a good practice?
Date
Msg-id 412BAA87.50808@mochima.com
Whole thread Raw
Responses Re: Is this legal SQL? Is it a good practice?
Re: Is this legal SQL? Is it a good practice?
List 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
--


pgsql-general by date:

Previous
From: Carlos Moreno
Date:
Subject: How is this possible? (more on deadlocks)
Next
From: Tom Lane
Date:
Subject: Re: Problem to connect to the Windows Port