|The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide
by The PostgreSQL Global Development Group
Paperback (6"x9"), 478 pages
RRP £14.95 ($19.95)
Sales of this book support the PostgreSQL project! Get a printed copy>>>
9.5.5 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 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) one or more rows, 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 successfully repositions the cursor, false otherwise.
FOUNDtrue if it iterates one or more times, else false. This applies to all four variants of the
FORloops, dynamic record-set
FORloops, and cursor
FOUNDis set this way when the
FORloop exits; inside the execution of the loop,
FOUNDis not modified by the
FORstatement, although it might be changed by the execution of other statements within the loop body.
RETURN QUERY EXECUTEstatements set
FOUNDtrue if the query returns at least one row, false if no row is returned.
Other PL/pgSQL statements do not change
the state of
Note in particular that
changes the output of
GET DIAGNOSTICS, but
does not change
FOUND is a local variable within each
PL/pgSQL function; any changes to it
affect only the current function.
|ISBN 9781906966065||The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide||See the print edition|