@@ -1441,28 +1441,56 @@ EXECUTE format('UPDATE tbl SET %I = $1 WHERE key = $2', colname)
1441
1441
GET <optional> CURRENT </optional> DIAGNOSTICS <replaceable>variable</replaceable> { = | := } <replaceable>item</replaceable> <optional> , ... </optional>;
1442
1442
</synopsis>
1443
1443
1444
- This command allows retrieval of system status indicators. Each
1445
- <replaceable>item</replaceable> is a key word identifying a status
1446
- value to be assigned to the specified variable (which should be
1447
- of the right data type to receive it). The currently available
1448
- status items are <varname>ROW_COUNT</>, the number of rows
1449
- processed by the last <acronym>SQL</acronym> command sent to
1450
- the <acronym>SQL</acronym> engine, and <varname>RESULT_OID</>,
1451
- the OID of the last row inserted by the most recent
1452
- <acronym>SQL</acronym> command. Note that <varname>RESULT_OID</>
1453
- is only useful after an <command>INSERT</command> command into a
1454
- table containing OIDs.
1455
- Colon-equal (<literal>:=</>) can be used instead of SQL-standard
1456
- <literal>=</> for <command>GET DIAGNOSTICS</>.
1457
- </para>
1458
-
1459
- <para>
1460
- An example:
1444
+ This command allows retrieval of system status indicators.
1445
+ <literal>CURRENT</> is a noise word (but see also <command>GET STACKED
1446
+ DIAGNOSTICS</command> in <xref linkend="plpgsql-exception-diagnostics">).
1447
+ Each <replaceable>item</replaceable> is a key word identifying a status
1448
+ value to be assigned to the specified <replaceable>variable</replaceable>
1449
+ (which should be of the right data type to receive it). The currently
1450
+ available status items are shown
1451
+ in <xref linkend="plpgsql-current-diagnostics-values">. Colon-equal
1452
+ (<literal>:=</>) can be used instead of the SQL-standard <literal>=</>
1453
+ token. An example:
1461
1454
<programlisting>
1462
1455
GET DIAGNOSTICS integer_var = ROW_COUNT;
1463
1456
</programlisting>
1464
1457
</para>
1465
1458
1459
+ <table id="plpgsql-current-diagnostics-values">
1460
+ <title>Available Diagnostics Items</title>
1461
+ <tgroup cols="3">
1462
+ <thead>
1463
+ <row>
1464
+ <entry>Name</entry>
1465
+ <entry>Type</entry>
1466
+ <entry>Description</entry>
1467
+ </row>
1468
+ </thead>
1469
+ <tbody>
1470
+ <row>
1471
+ <entry><varname>ROW_COUNT</varname></entry>
1472
+ <entry><type>bigint</></entry>
1473
+ <entry>the number of rows processed by the most
1474
+ recent <acronym>SQL</acronym> command</entry>
1475
+ </row>
1476
+ <row>
1477
+ <entry><varname>RESULT_OID</varname></entry>
1478
+ <entry><type>oid</></entry>
1479
+ <entry>the OID of the last row inserted by the most
1480
+ recent <acronym>SQL</acronym> command (only useful after
1481
+ an <command>INSERT</command> command into a table having
1482
+ OIDs)</entry>
1483
+ </row>
1484
+ <row>
1485
+ <entry><literal>PG_CONTEXT</literal></entry>
1486
+ <entry><type>text</></entry>
1487
+ <entry>line(s) of text describing the current call stack
1488
+ (see <xref linkend="plpgsql-call-stack">)</entry>
1489
+ </row>
1490
+ </tbody>
1491
+ </tgroup>
1492
+ </table>
1493
+
1466
1494
<para>
1467
1495
The second method to determine the effects of a command is to check the
1468
1496
special variable named <literal>FOUND</literal>, which is of
@@ -1828,13 +1856,13 @@ SELECT * FROM get_available_flightid(CURRENT_DATE);
1828
1856
<application>PL/pgSQL</> has three forms of <command>IF</>:
1829
1857
<itemizedlist>
1830
1858
<listitem>
1831
- <para><literal>IF ... THEN</></>
1859
+ <para><literal>IF ... THEN ... END IF </></>
1832
1860
</listitem>
1833
1861
<listitem>
1834
- <para><literal>IF ... THEN ... ELSE</></>
1862
+ <para><literal>IF ... THEN ... ELSE ... END IF </></>
1835
1863
</listitem>
1836
1864
<listitem>
1837
- <para><literal>IF ... THEN ... ELSIF ... THEN ... ELSE</></>
1865
+ <para><literal>IF ... THEN ... ELSIF ... THEN ... ELSE ... END IF </></>
1838
1866
</listitem>
1839
1867
</itemizedlist>
1840
1868
@@ -2699,13 +2727,14 @@ GET STACKED DIAGNOSTICS <replaceable>variable</replaceable> { = | := } <replacea
2699
2727
</synopsis>
2700
2728
2701
2729
Each <replaceable>item</replaceable> is a key word identifying a status
2702
- value to be assigned to the specified variable (which should be
2703
- of the right data type to receive it). The currently available
2704
- status items are shown in <xref linkend="plpgsql-exception-diagnostics-values">.
2730
+ value to be assigned to the specified <replaceable>variable</replaceable>
2731
+ (which should be of the right data type to receive it). The currently
2732
+ available status items are shown
2733
+ in <xref linkend="plpgsql-exception-diagnostics-values">.
2705
2734
</para>
2706
2735
2707
2736
<table id="plpgsql-exception-diagnostics-values">
2708
- <title>Error Diagnostics Values </title>
2737
+ <title>Error Diagnostics Items </title>
2709
2738
<tgroup cols="3">
2710
2739
<thead>
2711
2740
<row>
@@ -2717,53 +2746,54 @@ GET STACKED DIAGNOSTICS <replaceable>variable</replaceable> { = | := } <replacea
2717
2746
<tbody>
2718
2747
<row>
2719
2748
<entry><literal>RETURNED_SQLSTATE</literal></entry>
2720
- <entry>text</entry>
2749
+ <entry><type> text</> </entry>
2721
2750
<entry>the SQLSTATE error code of the exception</entry>
2722
2751
</row>
2723
2752
<row>
2724
2753
<entry><literal>COLUMN_NAME</literal></entry>
2725
- <entry>text</entry>
2754
+ <entry><type> text</> </entry>
2726
2755
<entry>the name of the column related to exception</entry>
2727
2756
</row>
2728
2757
<row>
2729
2758
<entry><literal>CONSTRAINT_NAME</literal></entry>
2730
- <entry>text</entry>
2759
+ <entry><type> text</> </entry>
2731
2760
<entry>the name of the constraint related to exception</entry>
2732
2761
</row>
2733
2762
<row>
2734
2763
<entry><literal>PG_DATATYPE_NAME</literal></entry>
2735
- <entry>text</entry>
2764
+ <entry><type> text</> </entry>
2736
2765
<entry>the name of the data type related to exception</entry>
2737
2766
</row>
2738
2767
<row>
2739
2768
<entry><literal>MESSAGE_TEXT</literal></entry>
2740
- <entry>text</entry>
2769
+ <entry><type> text</> </entry>
2741
2770
<entry>the text of the exception's primary message</entry>
2742
2771
</row>
2743
2772
<row>
2744
2773
<entry><literal>TABLE_NAME</literal></entry>
2745
- <entry>text</entry>
2774
+ <entry><type> text</> </entry>
2746
2775
<entry>the name of the table related to exception</entry>
2747
2776
</row>
2748
2777
<row>
2749
2778
<entry><literal>SCHEMA_NAME</literal></entry>
2750
- <entry>text</entry>
2779
+ <entry><type> text</> </entry>
2751
2780
<entry>the name of the schema related to exception</entry>
2752
2781
</row>
2753
2782
<row>
2754
2783
<entry><literal>PG_EXCEPTION_DETAIL</literal></entry>
2755
- <entry>text</entry>
2784
+ <entry><type> text</> </entry>
2756
2785
<entry>the text of the exception's detail message, if any</entry>
2757
2786
</row>
2758
2787
<row>
2759
2788
<entry><literal>PG_EXCEPTION_HINT</literal></entry>
2760
- <entry>text</entry>
2789
+ <entry><type> text</> </entry>
2761
2790
<entry>the text of the exception's hint message, if any</entry>
2762
2791
</row>
2763
2792
<row>
2764
2793
<entry><literal>PG_EXCEPTION_CONTEXT</literal></entry>
2765
- <entry>text</entry>
2766
- <entry>line(s) of text describing the call stack</entry>
2794
+ <entry><type>text</></entry>
2795
+ <entry>line(s) of text describing the call stack at the time of the
2796
+ exception (see <xref linkend="plpgsql-call-stack">)</entry>
2767
2797
</row>
2768
2798
</tbody>
2769
2799
</tgroup>
@@ -2794,26 +2824,19 @@ END;
2794
2824
</sect3>
2795
2825
</sect2>
2796
2826
2797
- <sect2 id="plpgsql-get-diagnostics-context ">
2798
- <title>Obtaining Current Execution Information</title>
2827
+ <sect2 id="plpgsql-call-stack ">
2828
+ <title>Obtaining Execution Location Information</title>
2799
2829
2800
2830
<para>
2801
- The <command>GET <optional> CURRENT </optional> DIAGNOSTICS</command>
2802
- command retrieves information about current execution state (whereas
2803
- the <command>GET STACKED DIAGNOSTICS</command> command discussed above
2804
- reports information about the execution state as of a previous error).
2805
- This command has the form:
2806
- </para>
2807
-
2808
- <synopsis>
2809
- GET <optional> CURRENT </optional> DIAGNOSTICS <replaceable>variable</replaceable> { = | := } <replaceable>item</replaceable> <optional> , ... </optional>;
2810
- </synopsis>
2811
-
2812
- <para>
2813
- Currently only one information item is supported. Status
2814
- item <literal>PG_CONTEXT</> will return a text string with line(s) of
2815
- text describing the call stack. The first line refers to the
2816
- current function and currently executing <command>GET DIAGNOSTICS</command>
2831
+ The <command>GET DIAGNOSTICS</command> command, previously described
2832
+ in <xref linkend="plpgsql-statements-diagnostics">, retrieves information
2833
+ about current execution state (whereas the <command>GET STACKED
2834
+ DIAGNOSTICS</command> command discussed above reports information about
2835
+ the execution state as of a previous error). Its <literal>PG_CONTEXT</>
2836
+ status item is useful for identifying the current execution
2837
+ location. <literal>PG_CONTEXT</> returns a text string with line(s)
2838
+ of text describing the call stack. The first line refers to the current
2839
+ function and currently executing <command>GET DIAGNOSTICS</command>
2817
2840
command. The second and any subsequent lines refer to calling functions
2818
2841
further up the call stack. For example:
2819
2842
@@ -2847,6 +2870,12 @@ CONTEXT: PL/pgSQL function outer_func() line 3 at RETURN
2847
2870
</programlisting>
2848
2871
2849
2872
</para>
2873
+
2874
+ <para>
2875
+ <literal>GET STACKED DIAGNOSTICS ... PG_EXCEPTION_CONTEXT</literal>
2876
+ returns the same sort of stack trace, but describing the location
2877
+ at which an error was detected, rather than the current location.
2878
+ </para>
2850
2879
</sect2>
2851
2880
</sect1>
2852
2881
@@ -4235,7 +4264,7 @@ SELECT * FROM sales_summary_bytime;
4235
4264
</para>
4236
4265
4237
4266
<para>
4238
- When a <application>PL/pgSQL</application> function is called as a
4267
+ When a <application>PL/pgSQL</application> function is called as an
4239
4268
event trigger, several special variables are created automatically
4240
4269
in the top-level block. They are:
4241
4270
@@ -4263,7 +4292,7 @@ SELECT * FROM sales_summary_bytime;
4263
4292
</para>
4264
4293
4265
4294
<para>
4266
- <xref linkend="plpgsql-event-trigger-example"> shows an example of a
4295
+ <xref linkend="plpgsql-event-trigger-example"> shows an example of an
4267
4296
event trigger procedure in <application>PL/pgSQL</application>.
4268
4297
</para>
4269
4298
0 commit comments