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

Commit 0898d71

Browse files
committed
Marginal improvements to documentation of plpgsql's OPEN cursor statement.
Rearrange text to improve clarity, and add an example of implicit reference to a plpgsql variable in a bound cursor's query. Byproduct of some work I'd done on the "named cursor parameters" patch before giving up on it.
1 parent b4aec38 commit 0898d71

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

doc/src/sgml/plpgsql.sgml

+28-16
Original file line numberDiff line numberDiff line change
@@ -2720,7 +2720,7 @@ END;
27202720
DECLARE
27212721
curs1 refcursor;
27222722
curs2 CURSOR FOR SELECT * FROM tenk1;
2723-
curs3 CURSOR (key integer) IS SELECT * FROM tenk1 WHERE unique1 = key;
2723+
curs3 CURSOR (key integer) FOR SELECT * FROM tenk1 WHERE unique1 = key;
27242724
</programlisting>
27252725
All three of these variables have the data type <type>refcursor</>,
27262726
but the first can be used with any query, while the second has
@@ -2836,31 +2836,43 @@ OPEN <replaceable>bound_cursorvar</replaceable> <optional> ( <replaceable>argume
28362836
cursor cannot be open already. A list of actual argument value
28372837
expressions must appear if and only if the cursor was declared to
28382838
take arguments. These values will be substituted in the query.
2839+
</para>
2840+
2841+
<para>
28392842
The query plan for a bound cursor is always considered cacheable;
28402843
there is no equivalent of <command>EXECUTE</command> in this case.
2841-
Notice that <literal>SCROLL</> and
2842-
<literal>NO SCROLL</> cannot be specified, as the cursor's scrolling
2844+
Notice that <literal>SCROLL</> and <literal>NO SCROLL</> cannot be
2845+
specified in <command>OPEN</>, as the cursor's scrolling
28432846
behavior was already determined.
28442847
</para>
28452848

28462849
<para>
2847-
Note that because variable substitution is done on the bound
2848-
cursor's query, there are two ways to pass values into the cursor:
2849-
either with an explicit argument to <command>OPEN</>, or
2850-
implicitly by referencing a <application>PL/pgSQL</> variable
2851-
in the query. However, only variables declared before the bound
2852-
cursor was declared will be substituted into it. In either case
2853-
the value to be passed is determined at the time of the
2854-
<command>OPEN</>.
2855-
</para>
2856-
2857-
<para>
2858-
Examples:
2850+
Examples (these use the cursor declaration examples above):
28592851
<programlisting>
28602852
OPEN curs2;
28612853
OPEN curs3(42);
28622854
</programlisting>
2863-
</para>
2855+
</para>
2856+
2857+
<para>
2858+
Because variable substitution is done on a bound cursor's query,
2859+
there are really two ways to pass values into the cursor: either
2860+
with an explicit argument to <command>OPEN</>, or implicitly by
2861+
referencing a <application>PL/pgSQL</> variable in the query.
2862+
However, only variables declared before the bound cursor was
2863+
declared will be substituted into it. In either case the value to
2864+
be passed is determined at the time of the <command>OPEN</>.
2865+
For example, another way to get the same effect as the
2866+
<literal>curs3</> example above is
2867+
<programlisting>
2868+
DECLARE
2869+
key integer;
2870+
curs4 CURSOR FOR SELECT * FROM tenk1 WHERE unique1 = key;
2871+
BEGIN
2872+
key := 42;
2873+
OPEN curs4;
2874+
</programlisting>
2875+
</para>
28642876
</sect3>
28652877
</sect2>
28662878

0 commit comments

Comments
 (0)