From c892643a3c4645450e3f84d2e2266a4e46340d28 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 16 Jun 2006 23:29:27 +0000 Subject: Code review for SELECT INTO STRICT patch: use saner choices of error SQLSTATEs, fix some documentation problems. --- doc/src/sgml/errcodes.sgml | 14 +++++++++++++- doc/src/sgml/plpgsql.sgml | 43 +++++++++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 19 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/errcodes.sgml b/doc/src/sgml/errcodes.sgml index b5617c98507..bf06cfaf5e5 100644 --- a/doc/src/sgml/errcodes.sgml +++ b/doc/src/sgml/errcodes.sgml @@ -1,4 +1,4 @@ - + <productname>PostgreSQL</productname> Error Codes @@ -1344,6 +1344,18 @@ raise_exception + +P0002 +NO DATA FOUND +no_data_found + + + +P0003 +TOO MANY ROWS +too_many_rows + + Class XX — Internal Error diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index 1f09b9e99c7..ac5b2b4cfc6 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -1,4 +1,4 @@ - + <application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language @@ -1076,8 +1076,8 @@ tax := subtotal * 0.06; - The result of a SELECT command yielding multiple columns (but - only one row) can be assigned to a record variable, row-type + The result of a SELECT 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: @@ -1126,23 +1126,24 @@ SELECT INTO STRICT target target will be set to the first row returned by the query, or if the query returned no rows, null values are assigned. (Note that the first row is not - well-defined unless you've used ORDER BY.) - You can check the special FOUND variable to - determine if any rows were found: + well-defined unless you've used ORDER BY.) Any result rows + after the first row are discarded. + You can check the special FOUND variable (see + ) to + determine whether a row was returned: -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; - - If the STRICT option is specified, a query must + If the STRICT option is specified, the query must return exactly one row or a run-time error will be thrown, either NO_DATA_FOUND (no rows) or 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: BEGIN; @@ -1154,11 +1155,17 @@ BEGIN; RAISE EXCEPTION 'employee % not unique', myname; END; - Only SELECT INTO STRICT allows you to check if more - than one row was retrieved. SELECT INTO STRICT - matches Oracle's PL/SQL SELECT INTO behavior. + Successful execution of SELECT INTO STRICT + always sets FOUND to true. + + + SELECT INTO STRICT matches the behavior of + Oracle PL/SQL's SELECT INTO statement. + + + @@ -1987,7 +1994,7 @@ END LOOP label ; the loop. If the BY clause isn't specified the iteration step is 1 otherwise it's the value specified in the BY clause. If REVERSE is specified then the step value is - considered negative. + considered negative. @@ -2764,7 +2771,7 @@ RAISE EXCEPTION 'Nonexistent ID --> %', user_id; Data type name; the name of the table that caused the trigger invocation. This is now deprecated, and could disappear in a future - release. Use TG_TABLE_NAME instead. + release. Use TG_TABLE_NAME instead. @@ -2774,7 +2781,7 @@ RAISE EXCEPTION 'Nonexistent ID --> %', user_id; Data type name; the name of the table that - caused the trigger invocation. + caused the trigger invocation. @@ -2784,7 +2791,7 @@ RAISE EXCEPTION 'Nonexistent ID --> %', user_id; Data type name; the name of the schema of the - table that caused the trigger invocation. + table that caused the trigger invocation. -- cgit v1.2.3