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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-general by date

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