Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ade64d0

Browse files
committed
Doc: improve discussion of plpgsql's GET DIAGNOSTICS, other minor fixes.
9.4 added a second description of GET DIAGNOSTICS that was totally independent of the existing one, resulting in each description lying to the extent that it claimed the set of status items it described was complete. Fix that, and do some minor markup improvement. Also some other small fixes per bug #14258 from Dilian Palauzov. Discussion: <20160718181437.1414.40802@wrigleys.postgresql.org>
1 parent 82bbfc7 commit ade64d0

File tree

2 files changed

+85
-56
lines changed

2 files changed

+85
-56
lines changed

doc/src/sgml/plpgsql.sgml

+84-55
Original file line numberDiff line numberDiff line change
@@ -1441,28 +1441,56 @@ EXECUTE format('UPDATE tbl SET %I = $1 WHERE key = $2', colname)
14411441
GET <optional> CURRENT </optional> DIAGNOSTICS <replaceable>variable</replaceable> { = | := } <replaceable>item</replaceable> <optional> , ... </optional>;
14421442
</synopsis>
14431443

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:
14611454
<programlisting>
14621455
GET DIAGNOSTICS integer_var = ROW_COUNT;
14631456
</programlisting>
14641457
</para>
14651458

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+
14661494
<para>
14671495
The second method to determine the effects of a command is to check the
14681496
special variable named <literal>FOUND</literal>, which is of
@@ -1828,13 +1856,13 @@ SELECT * FROM get_available_flightid(CURRENT_DATE);
18281856
<application>PL/pgSQL</> has three forms of <command>IF</>:
18291857
<itemizedlist>
18301858
<listitem>
1831-
<para><literal>IF ... THEN</></>
1859+
<para><literal>IF ... THEN ... END IF</></>
18321860
</listitem>
18331861
<listitem>
1834-
<para><literal>IF ... THEN ... ELSE</></>
1862+
<para><literal>IF ... THEN ... ELSE ... END IF</></>
18351863
</listitem>
18361864
<listitem>
1837-
<para><literal>IF ... THEN ... ELSIF ... THEN ... ELSE</></>
1865+
<para><literal>IF ... THEN ... ELSIF ... THEN ... ELSE ... END IF</></>
18381866
</listitem>
18391867
</itemizedlist>
18401868

@@ -2699,13 +2727,14 @@ GET STACKED DIAGNOSTICS <replaceable>variable</replaceable> { = | := } <replacea
26992727
</synopsis>
27002728

27012729
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">.
27052734
</para>
27062735

27072736
<table id="plpgsql-exception-diagnostics-values">
2708-
<title>Error Diagnostics Values</title>
2737+
<title>Error Diagnostics Items</title>
27092738
<tgroup cols="3">
27102739
<thead>
27112740
<row>
@@ -2717,53 +2746,54 @@ GET STACKED DIAGNOSTICS <replaceable>variable</replaceable> { = | := } <replacea
27172746
<tbody>
27182747
<row>
27192748
<entry><literal>RETURNED_SQLSTATE</literal></entry>
2720-
<entry>text</entry>
2749+
<entry><type>text</></entry>
27212750
<entry>the SQLSTATE error code of the exception</entry>
27222751
</row>
27232752
<row>
27242753
<entry><literal>COLUMN_NAME</literal></entry>
2725-
<entry>text</entry>
2754+
<entry><type>text</></entry>
27262755
<entry>the name of the column related to exception</entry>
27272756
</row>
27282757
<row>
27292758
<entry><literal>CONSTRAINT_NAME</literal></entry>
2730-
<entry>text</entry>
2759+
<entry><type>text</></entry>
27312760
<entry>the name of the constraint related to exception</entry>
27322761
</row>
27332762
<row>
27342763
<entry><literal>PG_DATATYPE_NAME</literal></entry>
2735-
<entry>text</entry>
2764+
<entry><type>text</></entry>
27362765
<entry>the name of the data type related to exception</entry>
27372766
</row>
27382767
<row>
27392768
<entry><literal>MESSAGE_TEXT</literal></entry>
2740-
<entry>text</entry>
2769+
<entry><type>text</></entry>
27412770
<entry>the text of the exception's primary message</entry>
27422771
</row>
27432772
<row>
27442773
<entry><literal>TABLE_NAME</literal></entry>
2745-
<entry>text</entry>
2774+
<entry><type>text</></entry>
27462775
<entry>the name of the table related to exception</entry>
27472776
</row>
27482777
<row>
27492778
<entry><literal>SCHEMA_NAME</literal></entry>
2750-
<entry>text</entry>
2779+
<entry><type>text</></entry>
27512780
<entry>the name of the schema related to exception</entry>
27522781
</row>
27532782
<row>
27542783
<entry><literal>PG_EXCEPTION_DETAIL</literal></entry>
2755-
<entry>text</entry>
2784+
<entry><type>text</></entry>
27562785
<entry>the text of the exception's detail message, if any</entry>
27572786
</row>
27582787
<row>
27592788
<entry><literal>PG_EXCEPTION_HINT</literal></entry>
2760-
<entry>text</entry>
2789+
<entry><type>text</></entry>
27612790
<entry>the text of the exception's hint message, if any</entry>
27622791
</row>
27632792
<row>
27642793
<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>
27672797
</row>
27682798
</tbody>
27692799
</tgroup>
@@ -2794,26 +2824,19 @@ END;
27942824
</sect3>
27952825
</sect2>
27962826

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>
27992829

28002830
<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>
28172840
command. The second and any subsequent lines refer to calling functions
28182841
further up the call stack. For example:
28192842

@@ -2847,6 +2870,12 @@ CONTEXT: PL/pgSQL function outer_func() line 3 at RETURN
28472870
</programlisting>
28482871

28492872
</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>
28502879
</sect2>
28512880
</sect1>
28522881

@@ -4235,7 +4264,7 @@ SELECT * FROM sales_summary_bytime;
42354264
</para>
42364265

42374266
<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
42394268
event trigger, several special variables are created automatically
42404269
in the top-level block. They are:
42414270

@@ -4263,7 +4292,7 @@ SELECT * FROM sales_summary_bytime;
42634292
</para>
42644293

42654294
<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
42674296
event trigger procedure in <application>PL/pgSQL</application>.
42684297
</para>
42694298

doc/src/sgml/release-9.4.sgml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7308,7 +7308,7 @@ Branch: REL9_4_STABLE [c2b06ab17] 2015-01-30 22:45:58 -0500
73087308
<listitem>
73097309
<para>
73107310
Add ability to retrieve the current PL/PgSQL call stack
7311-
using <link linkend="plpgsql-get-diagnostics-context"><command>GET
7311+
using <link linkend="plpgsql-call-stack"><command>GET
73127312
DIAGNOSTICS</></link>
73137313
(Pavel Stehule, Stephen Frost)
73147314
</para>

0 commit comments

Comments
 (0)