|
1 | | -<REFENTRY ID="SQL-DECLARESTATEMENT-1"> |
| 1 | +<REFENTRY ID="SQL-DECLARE"> |
2 | 2 | <REFMETA> |
3 | 3 | <REFENTRYTITLE> |
4 | | - DECLARE STATEMENT |
| 4 | + DECLARE |
5 | 5 | </REFENTRYTITLE> |
6 | 6 | <REFMISCINFO>SQL - Language Statements</REFMISCINFO> |
7 | 7 | </REFMETA> |
8 | 8 | <REFNAMEDIV> |
9 | 9 | <REFNAME> |
10 | | - DECLARE STATEMENT |
| 10 | + DECLARE |
11 | 11 | </REFNAME> |
12 | 12 | <REFPURPOSE> |
13 | | -Declares a cursor |
| 13 | +Defines a cursor for table access |
14 | 14 | </REFPURPOSE> |
15 | 15 | <REFSYNOPSISDIV> |
16 | 16 | <REFSYNOPSISDIVINFO> |
17 | | - <DATE>1998-04-15</DATE> |
| 17 | + <DATE>1998-09-04</DATE> |
18 | 18 | </REFSYNOPSISDIVINFO> |
19 | 19 | <SYNOPSIS> |
20 | | - DECLARE <replaceable class="parameter">cursor</replaceable> [ BINARY ] |
21 | | - FOR SELECT <replaceable class="parameter">query</replaceable> |
| 20 | +DECLARE <replaceable class="parameter">cursor</replaceable> [ BINARY ] [ INSENSITIVE ] [ SCROLL ] |
| 21 | + CURSOR FOR <replaceable class="parameter">query</replaceable> |
| 22 | + [ FOR { READ ONLY | UPDATE [ OF <replaceable class="parameter">column</replaceable> [, ...] ] ] |
22 | 23 | </SYNOPSIS> |
23 | | - <REFSECT2 ID="R2-SQL-DECLARESTATEMENT-1"> |
| 24 | + <REFSECT2 ID="R2-SQL-DECLARE-1"> |
24 | 25 | <REFSECT2INFO> |
25 | 26 | <DATE>1998-04-15</DATE> |
26 | 27 | </REFSECT2INFO> |
|
29 | 30 | </TITLE> |
30 | 31 | <PARA> |
31 | 32 | </PARA> |
32 | | - <VARIABLELIST> |
33 | | - <VARLISTENTRY> |
34 | | - <TERM> |
35 | | - </TERM> |
36 | | - <LISTITEM> |
37 | | - <PARA> |
38 | 33 | <VARIABLELIST> |
39 | 34 | <VARLISTENTRY> |
40 | 35 | <TERM> |
41 | | - <ReturnValue>BINARY</ReturnValue> |
| 36 | +<replaceable class="parameter">cursor</replaceable> |
42 | 37 | </TERM> |
43 | 38 | <LISTITEM> |
44 | 39 | <PARA> |
45 | | - The BINARY keyword causes the cursor to fetch data in binary |
46 | | - rather than in ASCII format. |
| 40 | + The name of the cursor to be used in subsequent FETCH operations.. |
47 | 41 | </PARA> |
48 | 42 | </LISTITEM> |
49 | 43 | </VARLISTENTRY> |
| 44 | + |
50 | 45 | <VARLISTENTRY> |
51 | 46 | <TERM> |
52 | | - <ReturnValue><replaceable class="parameter">cursor</replaceable></ReturnValue> |
| 47 | +BINARY |
53 | 48 | </TERM> |
54 | 49 | <LISTITEM> |
55 | 50 | <PARA> |
56 | | - The cursor's name. |
| 51 | + Causes the cursor to fetch data in binary |
| 52 | + rather than in text format. |
57 | 53 | </PARA> |
58 | 54 | </LISTITEM> |
59 | 55 | </VARLISTENTRY> |
| 56 | + |
60 | 57 | <VARLISTENTRY> |
61 | 58 | <TERM> |
62 | | - <ReturnValue><replaceable class="parameter">query</replaceable></ReturnValue> |
| 59 | +INSENSITIVE |
63 | 60 | </TERM> |
64 | 61 | <LISTITEM> |
65 | 62 | <PARA> |
66 | | - An SQL query which will provide the rows to be governed by the |
67 | | - cursor. |
| 63 | + <acronym>SQL92</acronym> keyword indicating that data retrieved |
| 64 | +from the cursor should be unaffected by updates from other processes or cursors. |
| 65 | +Since cursor operations occur within transactions |
| 66 | + in <productname>Postgres</productname> this is always the case. |
| 67 | +This keyword has no effect. |
| 68 | + </PARA> |
| 69 | + </LISTITEM> |
| 70 | +</VARLISTENTRY> |
| 71 | + |
| 72 | +<VARLISTENTRY> |
| 73 | + <TERM> |
| 74 | + SCROLL |
| 75 | + </TERM> |
| 76 | + <LISTITEM> |
| 77 | + <PARA> |
| 78 | +<acronym>SQL92</acronym> keyword indicating that data may be retrieved |
| 79 | +in multiple rows per FETCH operation. Since this is allowed at all times |
| 80 | +by <productname>Postgres</productname> this keyword has no effect. |
68 | 81 | </PARA> |
| 82 | + </LISTITEM> |
| 83 | +</VARLISTENTRY> |
| 84 | + |
| 85 | +<VARLISTENTRY> |
| 86 | + <TERM> |
| 87 | + <replaceable class="parameter">query</replaceable> |
| 88 | + </TERM> |
| 89 | + <LISTITEM> |
69 | 90 | <PARA> |
| 91 | + An SQL query which will provide the rows to be governed by the |
| 92 | + cursor. |
70 | 93 | Refer to the SELECT statement for further information about |
71 | 94 | valid arguments. |
72 | 95 | </PARA> |
73 | 96 | </LISTITEM> |
74 | 97 | </VARLISTENTRY> |
75 | | - </variablelist> |
76 | | - </LISTITEM> |
77 | | - </VARLISTENTRY> |
| 98 | + |
| 99 | +<VARLISTENTRY> |
| 100 | + <TERM> |
| 101 | + READ ONLY |
| 102 | + </TERM> |
| 103 | + <LISTITEM> |
| 104 | + <PARA> |
| 105 | +<acronym>SQL92</acronym> keyword indicating that the cursor will be used |
| 106 | +in a readonly mode. Since this is the only cursor access mode |
| 107 | +available in <productname>Postgres</productname> this keyword has no effect. |
| 108 | + </PARA> |
| 109 | + </LISTITEM> |
| 110 | +</VARLISTENTRY> |
| 111 | + |
| 112 | +<VARLISTENTRY> |
| 113 | + <TERM> |
| 114 | + UPDATE |
| 115 | + </TERM> |
| 116 | + <LISTITEM> |
| 117 | + <PARA> |
| 118 | +<acronym>SQL92</acronym> keyword indicating that the cursor will be used |
| 119 | +to update tables. Since cursor updates are not currently |
| 120 | +supported in <productname>Postgres</productname> this keyword |
| 121 | +provokes an informational error message. |
| 122 | + </PARA> |
| 123 | + </LISTITEM> |
| 124 | +</VARLISTENTRY> |
| 125 | + |
| 126 | +<VARLISTENTRY> |
| 127 | + <TERM> |
| 128 | + <replaceable class="parameter">column</replaceable> |
| 129 | + </TERM> |
| 130 | + <LISTITEM> |
| 131 | + <PARA> |
| 132 | +Column(s) to be updated. |
| 133 | +Since cursor updates are not currently |
| 134 | +supported in <productname>Postgres</productname> the UPDATE clause |
| 135 | +provokes an informational error message. |
| 136 | + </PARA> |
| 137 | + </LISTITEM> |
| 138 | +</VARLISTENTRY> |
| 139 | + |
78 | 140 | </VARIABLELIST> |
79 | 141 | </REFSECT2> |
80 | 142 |
|
81 | | - <REFSECT2 ID="R2-SQL-DECLARESTATEMENT-2"> |
| 143 | + <REFSECT2 ID="R2-SQL-DECLARE-2"> |
82 | 144 | <REFSECT2INFO> |
83 | 145 | <DATE>1998-04-15</DATE> |
84 | 146 | </REFSECT2INFO> |
|
87 | 149 | </TITLE> |
88 | 150 | <PARA> |
89 | 151 | </PARA> |
| 152 | + |
90 | 153 | <VARIABLELIST> |
91 | | - <VARLISTENTRY> |
92 | | - <TERM> |
93 | | - </TERM> |
94 | | - <LISTITEM> |
95 | | - <PARA> |
96 | | - <VARIABLELIST> |
97 | 154 | <VARLISTENTRY> |
98 | 155 | <TERM> |
99 | | - <ReturnValue>SELECT</ReturnValue> |
| 156 | + SELECT |
100 | 157 | </TERM> |
101 | 158 | <LISTITEM> |
102 | 159 | <PARA> |
103 | 160 | The message returned if the SELECT is run successfully. |
104 | 161 | </PARA> |
105 | 162 | </LISTITEM> |
106 | 163 | </VARLISTENTRY> |
| 164 | + |
107 | 165 | <VARLISTENTRY> |
108 | 166 | <TERM> |
109 | | -<ReturnValue>NOTICE |
110 | | - BlankPortalAssignName: portal "<replaceable class="parameter">cursor</replaceable>" already exists</ReturnValue> |
| 167 | +NOTICE |
| 168 | + BlankPortalAssignName: portal "<replaceable class="parameter">cursor</replaceable>" already exists |
111 | 169 | </TERM> |
112 | 170 | <LISTITEM> |
113 | 171 | <PARA> |
114 | 172 | This error occurs if cursor "<replaceable class="parameter">cursor</replaceable>" is already declared. |
115 | 173 | </PARA> |
116 | 174 | </LISTITEM> |
117 | 175 | </VARLISTENTRY> |
118 | | - </variablelist> |
119 | | - </LISTITEM> |
120 | | - </VARLISTENTRY> |
| 176 | + |
| 177 | +<VARLISTENTRY> |
| 178 | + <TERM> |
| 179 | +ERROR: Named portals may only be used in begin/end transaction blocks |
| 180 | + </TERM> |
| 181 | + <LISTITEM> |
| 182 | + <PARA> |
| 183 | +This error occurs if the cursor is not declared within a transaction block. |
| 184 | + </PARA> |
| 185 | + </LISTITEM> |
| 186 | +</VARLISTENTRY> |
| 187 | + |
121 | 188 | </VARIABLELIST> |
122 | 189 | </REFSECT2> |
123 | 190 | </REFSYNOPSISDIV> |
124 | 191 |
|
125 | | - <REFSECT1 ID="R1-SQL-DECLARESTATEMENT-1"> |
| 192 | + <REFSECT1 ID="R1-SQL-DECLARE-1"> |
126 | 193 | <REFSECT1INFO> |
127 | | - <DATE>1998-04-15</DATE> |
| 194 | + <DATE>1998-09-04</DATE> |
128 | 195 | </REFSECT1INFO> |
129 | 196 | <TITLE> |
130 | 197 | Description |
131 | 198 | </TITLE> |
132 | 199 | <PARA> |
133 | 200 | DECLARE allows a user to create cursors, which can be used to retrieve |
134 | 201 | a small number of rows at a time out of a larger query. Cursors can return |
135 | | - data either inASCII or in binary foramt. |
| 202 | + data either intext or in binary foramt. |
136 | 203 | </PARA> |
137 | 204 | <PARA> |
138 | | - Normal cursors return data in ASCII format. Since |
| 205 | + Normal cursors return data in text format, either ASCII or another |
| 206 | +encoding scheme depending on how the <productname>Postgres</productname> |
| 207 | +backend was built. Since |
139 | 208 | data is stored natively in binary format, the system must |
140 | | - do a conversion to produce theASCII format. In addition, |
141 | | -ASCII formats are often larger in size than binary format. |
142 | | - Once the information comes back inASCII, the client |
143 | | - applicationoften has to convert it to a binary format to |
| 209 | + do a conversion to produce thetext format. In addition, |
| 210 | +text formats are often larger in size than the corresponding binary format. |
| 211 | + Once the information comes back intext form, the client |
| 212 | + applicationmay have to convert it to a binary format to |
144 | 213 | manipulate it anyway. |
145 | 214 | </PARA> |
146 | 215 | <PARA> |
147 | 216 | BINARY cursors give you back the data in the native binary |
148 | 217 | representation. So binary cursors will tend to be a |
149 | 218 | little faster since they suffer less conversion overhead. |
150 | | - For example, for an integer column, you get a C integer number like ^A |
151 | | - using a binary cursor, while you get a string value like '1' |
152 | | - using the non binary cursor. |
153 | | - </PARA> |
| 219 | +<para> |
| 220 | + As an example, if a query returns a value of one from an integer column, |
| 221 | +you would get a string of '1' with a default cursor |
| 222 | +whereas with a binary cursor you would get |
| 223 | + a 4-byte value equal to control-A ('^A'). |
| 224 | + |
| 225 | +<caution> |
| 226 | +<para> |
| 227 | +BINARY cursors should be used carefully. User applications such |
| 228 | +as <application>psql</application> are not aware of binary cursors |
| 229 | +and expect data to come back in a text format. |
| 230 | +</caution> |
| 231 | + |
154 | 232 | <PARA> |
155 | | - However,ASCII is architecture-neutral whereas binary |
| 233 | + However,string representation is architecture-neutral whereas binary |
156 | 234 | representation can differ between different machine architectures. |
157 | 235 | Therefore, if your client machine and server machine use different |
158 | | - representations, you will probably not want your data returned in |
| 236 | + representations (e.g. "big-endian" versus "little-endian"), |
| 237 | + you will probably not want your data returned in |
159 | 238 | binary format. |
160 | | - Again, if you intend to display the data in |
| 239 | + |
| 240 | +<tip> |
| 241 | +<para> |
| 242 | + If you intend to display the data in |
161 | 243 | ASCII, getting it back in ASCII will save you some |
162 | 244 | effort on the client side. |
| 245 | +</tip> |
163 | 246 | </PARA> |
164 | 247 |
|
165 | | - <REFSECT2 ID="R2-SQL-DECLARESTATEMENT-3"> |
| 248 | + <REFSECT2 ID="R2-SQL-DECLARE-3"> |
166 | 249 | <REFSECT2INFO> |
167 | | - <DATE>1998-04-15</DATE> |
| 250 | + <DATE>1998-09-04</DATE> |
168 | 251 | </REFSECT2INFO> |
169 | 252 | <TITLE> |
170 | 253 | Notes |
|
173 | 256 | Cursors are only available in transactions. |
174 | 257 | </PARA> |
175 | 258 | <PARA> |
176 | | - PostgreSQL does not have an explicit <command>OPEN cursor</command> |
177 | | - statement; a cursor is considered to be open when it is DECLAREd. |
| 259 | + <productname>Postgres</productname> |
| 260 | + does not have an explicit <command>OPEN cursor</command> |
| 261 | + statement; a cursor is considered to be open when it is declared. |
178 | 262 | </PARA> |
179 | 263 | </REFSECT2> |
180 | 264 | </refsect1> |
|
207 | 291 | SQL92 |
208 | 292 | </TITLE> |
209 | 293 | <PARA> |
210 | | - SQL92 specifies some additional capabilities for the DECLARE statement: |
211 | | - </PARA> |
212 | | - <synopsis> |
213 | | - DECLARE cursor [ INSENSITIVE ] [ SCROLL ] CURSOR |
214 | | - FOR SELECT expression |
215 | | - [ ORDER BY column [, ... ] [ ASC | DESC ] |
216 | | - [ FOR { READ ONLY | UPDATE [ OF column [, ...] ] } ] |
217 | | - </synopsis> |
218 | | - <variablelist> |
219 | | - <varlistentry> |
220 | | - <term></term> |
221 | | - <listitem> |
222 | | - <variablelist> |
223 | | - <varlistentry> |
224 | | -<term>INSENSITIVE</term> |
225 | | -<listitem> |
226 | | - <para> |
227 | | - UPDATE and DELETE CURRENT operations are not allowed |
228 | | - if the cursor is declared to be INSENSITIVE. |
229 | | - </para> |
230 | | -</listitem> |
231 | | - </varlistentry> |
232 | | - <varlistentry> |
233 | | -<term>SCROLL</term> |
234 | | -<listitem> |
235 | | - <para> |
236 | | - If SCROLL is not specified, only FETCH NEXT will be allowed. |
237 | | - </para> |
238 | | -</listitem> |
239 | | - </varlistentry> |
240 | | - <varlistentry> |
241 | | -<term>FOR READ ONLY/UPDATE</term> |
242 | | -<listitem> |
243 | | - <para> |
244 | | - If READ ONLY is specified, UPDATE/DELETE CURRENT operations |
245 | | - will not be allowed. |
246 | | - </para> |
247 | | -</listitem> |
248 | | - </varlistentry> |
249 | | - </variablelist> |
250 | | - </listitem> |
251 | | - </varlistentry> |
252 | | - </variablelist> |
| 294 | +<acronym>SQL92</acronym> allows cursors only in embedded <acronym>SQL</acronym> |
| 295 | +and in modules. <productname>Postgres</productname> permits cursors to be used |
| 296 | +interactively. |
| 297 | +<acronym>SQL92</acronym> allows embedded or modular cursors to |
| 298 | +update database information. |
| 299 | +All <productname>Postgres</productname> cursors are readonly. |
| 300 | +The BINARY keyword is a <productname>Postgres</productname> extension. |
| 301 | + |
253 | 302 | </REFENTRY> |
254 | 303 |
|
255 | 304 | <!-- Keep this comment at the end of the file |
|