|PostgreSQL Reference Manual - Volume 2 - Programming Guide|
by The PostgreSQL Global Development Group
Paperback (6"x9"), 408 pages
RRP £19.95 ($34.95)
Sales of this book support the PostgreSQL project! Get a printed copy>>>
9.6.6 Obtaining the Result Status
There are several ways to determine the effect of a command. The
first method is to use the
command, which has the form:
GET DIAGNOSTICS variable = item [ , ... ];
This command allows retrieval of system status indicators. Each
item is a key word identifying a state
value to be assigned to the specified variable (which should be
of the right data type to receive it). The currently available
status items are
ROW_COUNT, the number of rows
processed by the last SQL command sent down to
the SQL engine, and
the OID of the last row inserted by the most recent
SQL command. Note that
is only useful after an
INSERT command into a
table containing OIDs.
GET DIAGNOSTICS integer_var = ROW_COUNT;
The second method to determine the effects of a command is to check the
special variable named
FOUND, which is of
FOUND starts out
false within each PL/pgSQL function call.
It is set by each of the following types of statements:
SELECT INTOstatement sets
FOUNDtrue if a row is assigned, false if no row is returned.
FOUNDtrue if it produces (and discards) a row, false if no row is produced.
FOUNDtrue if at least one row is affected, false if no row is affected.
FOUNDtrue if it returns a row, false if no row is returned.
FOUNDtrue if it iterates one or more times, else false. This applies to all three variants of the
FORloops, and dynamic record-set
FOUNDis set this way when the
FORloop exits; inside the execution of the loop,
FOUNDis not modified by the
FORstatement, although it may be changed by the execution of other statements within the loop body.
FOUND is a local variable within each
PL/pgSQL function; any changes to it
affect only the current function.
|ISBN 0954612035||PostgreSQL Reference Manual - Volume 2 - Programming Guide||See the print edition|