@@ -1078,15 +1078,26 @@ END;
1078
1078
always sets <literal>FOUND</literal> to true.
1079
1079
</para>
1080
1080
1081
+ <para>
1082
+ For <command>INSERT</>/<command>UPDATE</>/<command>DELETE</> with
1083
+ <literal>RETURNING</>, <application>PL/pgSQL</application> reports
1084
+ an error for more than one returned row, even when
1085
+ <literal>STRICT</literal> is not specified. This is because there
1086
+ is no option such as <literal>ORDER BY</> with which to determine
1087
+ which affected row should be returned.
1088
+ </para>
1089
+
1081
1090
<para>
1082
1091
If <literal>print_strict_params</> is enabled for the function,
1083
- you will get information about the parameters passed to the
1084
- query in the <literal>DETAIL</> part of the error message produced
1085
- when the requirements of STRICT are not met. You can change this
1086
- setting on a system-wide basis by setting
1092
+ then when an error is thrown because the requirements
1093
+ of <literal>STRICT</> are not met, the <literal>DETAIL</> part of
1094
+ the error message will include information about the parameters
1095
+ passed to the query.
1096
+ You can change the <literal>print_strict_params</>
1097
+ setting for all functions by setting
1087
1098
<varname>plpgsql.print_strict_params</>, though only subsequent
1088
1099
function compilations will be affected. You can also enable it
1089
- on a per-function basis by using a compiler option:
1100
+ on a per-function basis by using a compiler option, for example :
1090
1101
<programlisting>
1091
1102
CREATE FUNCTION get_userid(username text) RETURNS int
1092
1103
AS $$
@@ -1100,15 +1111,12 @@ BEGIN
1100
1111
END
1101
1112
$$ LANGUAGE plpgsql;
1102
1113
</programlisting>
1103
- </para>
1104
-
1105
- <para>
1106
- For <command>INSERT</>/<command>UPDATE</>/<command>DELETE</> with
1107
- <literal>RETURNING</>, <application>PL/pgSQL</application> reports
1108
- an error for more than one returned row, even when
1109
- <literal>STRICT</literal> is not specified. This is because there
1110
- is no option such as <literal>ORDER BY</> with which to determine
1111
- which affected row should be returned.
1114
+ On failure, this function might produce an error message such as
1115
+ <programlisting>
1116
+ ERROR: query returned no rows
1117
+ DETAIL: parameters: $1 = 'nosuchuser'
1118
+ CONTEXT: PL/pgSQL function get_userid(text) line 6 at SQL statement
1119
+ </programlisting>
1112
1120
</para>
1113
1121
1114
1122
<note>
@@ -2767,28 +2775,36 @@ END;
2767
2775
</sect2>
2768
2776
2769
2777
<sect2 id="plpgsql-get-diagnostics-context">
2770
- <title>Obtaining the Call Stack Context Information</title>
2778
+ <title>Obtaining Current Execution Information</title>
2779
+
2780
+ <para>
2781
+ The <command>GET <optional> CURRENT </optional> DIAGNOSTICS</command>
2782
+ command retrieves information about current execution state (whereas
2783
+ the <command>GET STACKED DIAGNOSTICS</command> command discussed above
2784
+ reports information about the execution state as of a previous error).
2785
+ This command has the form:
2786
+ </para>
2771
2787
2772
2788
<synopsis>
2773
- GET <optional> CURRENT </optional> DIAGNOSTICS <replaceable>variable</replaceable> { = | := } <replaceable>PG_CONTEXT </replaceable> <optional> , ... </optional>;
2789
+ GET <optional> CURRENT </optional> DIAGNOSTICS <replaceable>variable</replaceable> { = | := } <replaceable>item </replaceable> <optional> , ... </optional>;
2774
2790
</synopsis>
2775
2791
2776
2792
<para>
2777
- Calling <command>GET DIAGNOSTICS</command> with status
2778
- item <varname >PG_CONTEXT</> will return a text string with line(s) of
2779
- text describing the call stack. The first row refers to the
2793
+ Currently only one information item is supported. Status
2794
+ item <literal >PG_CONTEXT</> will return a text string with line(s) of
2795
+ text describing the call stack. The first line refers to the
2780
2796
current function and currently executing <command>GET DIAGNOSTICS</command>
2781
- command. The second and any subsequent rows refer to the calling functions
2782
- up the call stack.
2797
+ command. The second and any subsequent lines refer to calling functions
2798
+ further up the call stack. For example:
2783
2799
2784
2800
<programlisting>
2785
- CREATE OR REPLACE FUNCTION public. outer_func() RETURNS integer AS $$
2801
+ CREATE OR REPLACE FUNCTION outer_func() RETURNS integer AS $$
2786
2802
BEGIN
2787
2803
RETURN inner_func();
2788
2804
END;
2789
2805
$$ LANGUAGE plpgsql;
2790
2806
2791
- CREATE OR REPLACE FUNCTION public. inner_func() RETURNS integer AS $$
2807
+ CREATE OR REPLACE FUNCTION inner_func() RETURNS integer AS $$
2792
2808
DECLARE
2793
2809
stack text;
2794
2810
BEGIN
@@ -2801,8 +2817,9 @@ $$ LANGUAGE plpgsql;
2801
2817
SELECT outer_func();
2802
2818
2803
2819
NOTICE: --- Call Stack ---
2804
- PL/pgSQL function inner_func() line 4 at GET DIAGNOSTICS
2820
+ PL/pgSQL function inner_func() line 5 at GET DIAGNOSTICS
2805
2821
PL/pgSQL function outer_func() line 3 at RETURN
2822
+ CONTEXT: PL/pgSQL function outer_func() line 3 at RETURN
2806
2823
outer_func
2807
2824
------------
2808
2825
1
0 commit comments