Is this legal SQL? Is it a good practice?

Поиск
Список
Период
Сортировка
От Carlos Moreno
Тема Is this legal SQL? Is it a good practice?
Дата
Msg-id 412BAA87.50808@mochima.com
обсуждение исходный текст
Ответы Re: Is this legal SQL? Is it a good practice?  (Peter Eisentraut <peter_e@gmx.net>)
Re: Is this legal SQL? Is it a good practice?  (Bill Harper <bharper@solutionst.com>)
Список 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 по дате отправления:

Предыдущее
От: Carlos Moreno
Дата:
Сообщение: How is this possible? (more on deadlocks)
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Problem to connect to the Windows Port