</indexterm>
<para>
- The result of a <command>SELECT</command> command yielding multiple columns (but
- only one row) can be assigned to a record variable, row-type
+ The result of a <command>SELECT</command> command yielding multiple
+ columns (but only one row) can be assigned to a record variable, row-type
variable, or list of scalar variables. This is done by:
<synopsis>
<replaceable>target</replaceable> will be set to the first row
returned by the query, or if the query returned no rows,
null values are assigned. (Note that <quote>the first row</> is not
- well-defined unless you've used <literal>ORDER BY</>.)
- You can check the special <literal>FOUND</literal> variable to
- determine if any rows were found:
+ well-defined unless you've used <literal>ORDER BY</>.) Any result rows
+ after the first row are discarded.
+ You can check the special <literal>FOUND</literal> variable (see
+ <xref linkend="plpgsql-statements-diagnostics">) to
+ determine whether a row was returned:
<programlisting>
-SELECT INTO STRICT myrec * FROM emp WHERE empname = myname;
+SELECT INTO myrec * FROM emp WHERE empname = myname;
IF NOT FOUND THEN
RAISE EXCEPTION 'employee % not found', myname;
END IF;
</programlisting>
- <para>
- If the <literal>STRICT</literal> option is specified, a query must
+ If the <literal>STRICT</literal> option is specified, the query must
return exactly one row or a run-time error will be thrown, either
<literal>NO_DATA_FOUND</> (no rows) or <literal>TOO_MANY_ROWS</>
- (more than one row). You can must use exception blocks to determine
- the number of rows generated by the query:
+ (more than one row). You can use an exception block if you wish
+ to catch the error, for example:
<programlisting>
BEGIN;
RAISE EXCEPTION 'employee % not unique', myname;
END;
</programlisting>
- Only <command>SELECT INTO STRICT</command> allows you to check if more
- than one row was retrieved. <command>SELECT INTO STRICT</command>
- matches Oracle's PL/SQL <command>SELECT INTO</command> behavior.
+ Successful execution of <command>SELECT INTO STRICT</command>
+ always sets <literal>FOUND</literal> to true.
</para>
+ <note>
+ <para>
+ <command>SELECT INTO STRICT</command> matches the behavior of
+ Oracle PL/SQL's <command>SELECT INTO</command> statement.
+ </para>
+ </note>
+
</sect2>
<sect2 id="plpgsql-statements-perform">
the loop. If the <literal>BY</> clause isn't specified the iteration
step is 1 otherwise it's the value specified in the <literal>BY</>
clause. If <literal>REVERSE</> is specified then the step value is
- considered negative.
+ considered negative.
</para>
<para>
<para>
Data type <type>name</type>; the name of the table that caused the trigger
invocation. This is now deprecated, and could disappear in a future
- release. Use <literal>TG_TABLE_NAME</> instead.
+ release. Use <literal>TG_TABLE_NAME</> instead.
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Data type <type>name</type>; the name of the table that
- caused the trigger invocation.
+ caused the trigger invocation.
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Data type <type>name</type>; the name of the schema of the
- table that caused the trigger invocation.
+ table that caused the trigger invocation.
</para>
</listitem>
</varlistentry>
/* Class P0 - PL/pgSQL Error (PostgreSQL-specific error class) */
#define ERRCODE_PLPGSQL_ERROR MAKE_SQLSTATE('P','0', '0','0','0')
#define ERRCODE_RAISE_EXCEPTION MAKE_SQLSTATE('P','0', '0','0','1')
+#define ERRCODE_NO_DATA_FOUND MAKE_SQLSTATE('P','0', '0','0','2')
+#define ERRCODE_TOO_MANY_ROWS MAKE_SQLSTATE('P','0', '0','0','3')
/* Class XX - Internal Error (PostgreSQL-specific error class) */
/* (this is for "can't-happen" conditions and software bugs) */
},
{
- "internal_error", ERRCODE_INTERNAL_ERROR
+ "no_data_found", ERRCODE_NO_DATA_FOUND
},
{
- "data_corrupted", ERRCODE_DATA_CORRUPTED
+ "too_many_rows", ERRCODE_TOO_MANY_ROWS
},
{
- "index_corrupted", ERRCODE_INDEX_CORRUPTED
+ "internal_error", ERRCODE_INTERNAL_ERROR
},
{
- "no_data_found", ERRCODE_NO_DATA
+ "data_corrupted", ERRCODE_DATA_CORRUPTED
},
{
- "too_many_rows", ERRCODE_CARDINALITY_VIOLATION
+ "index_corrupted", ERRCODE_INDEX_CORRUPTED
},
-
-