@@ -2720,7 +2720,7 @@ END;
2720
2720
DECLARE
2721
2721
curs1 refcursor;
2722
2722
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;
2724
2724
</programlisting>
2725
2725
All three of these variables have the data type <type>refcursor</>,
2726
2726
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
2836
2836
cursor cannot be open already. A list of actual argument value
2837
2837
expressions must appear if and only if the cursor was declared to
2838
2838
take arguments. These values will be substituted in the query.
2839
+ </para>
2840
+
2841
+ <para>
2839
2842
The query plan for a bound cursor is always considered cacheable;
2840
2843
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
2843
2846
behavior was already determined.
2844
2847
</para>
2845
2848
2846
2849
<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):
2859
2851
<programlisting>
2860
2852
OPEN curs2;
2861
2853
OPEN curs3(42);
2862
2854
</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>
2864
2876
</sect3>
2865
2877
</sect2>
2866
2878
0 commit comments