Re: returned value from SQL statement - Mailing list pgsql-general

From Albe Laurenz
Subject Re: returned value from SQL statement
Date
Msg-id D960CB61B694CF459DCFB4B0128514C201ED1BAC@exadv11.host.magwien.gv.at
Whole thread Raw
In response to returned value from SQL statement  ("Alain Roger" <raf.news@gmail.com>)
List pgsql-general
Alain Roger wrote:
> i would like to know how can i control the returned value from a SQL statement ?
> for example, if i do an INSERT INTO... :
> 1. how can i know if the INSERT worked ?
> i mean i already trapped the unicity violation, but what if
> there is another error ? where can i get a complete list of
> exceptions ?

You can get almost every error message from an INSERT.
A few examples: 53100 (DISK FULL), 22004 (NULL VALUE NOT ALLOWED), ...
There could be a trigger or a rule involved which could
basically do anything in the database...

> 2. if the INSERT INTO is successful, how can i know it ? what
> is the returned value ?

"Returned" sounds like you are referring to a specific API.
Which programming language do you use?
An INSERT statement is successful iff it does not generate an error message.
Of course, this does not necessarily imply that something
was inserted - e.g., if there is an INSTEAD DO NOTHING rule
on the table.

> 3. the same question as point 2 but for all SQL statements
> from PostgreSQL.

Similar: an statement is successful iff it does not generate an error message.
I'd say that's the definition of a successful statement.
As to the return value, that depends on the kind of statement:
A DELETE (without RETURNING) or CREATE TABLE statement will not return rows,
while a SELECT or a DELETE ... RETURNING will.

Yours,
Laurenz Albe

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Using tables in other PostGreSQL database
Next
From: Brad Nicholson
Date:
Subject: Re: page is uninitialized --- fixing