Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit95af0cb

Browse files
author
Thomas G. Lockhart
committed
Fix Postgres to support SQL92 syntax. Old syntax still works too.
1 parent4dce924 commit95af0cb

File tree

3 files changed

+269
-284
lines changed

3 files changed

+269
-284
lines changed

‎doc/src/sgml/ref/declare.sgml

Lines changed: 149 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
<REFENTRY ID="SQL-DECLARESTATEMENT-1">
1+
<REFENTRY ID="SQL-DECLARE">
22
<REFMETA>
33
<REFENTRYTITLE>
4-
DECLARE STATEMENT
4+
DECLARE
55
</REFENTRYTITLE>
66
<REFMISCINFO>SQL - Language Statements</REFMISCINFO>
77
</REFMETA>
88
<REFNAMEDIV>
99
<REFNAME>
10-
DECLARE STATEMENT
10+
DECLARE
1111
</REFNAME>
1212
<REFPURPOSE>
13-
Declares a cursor
13+
Defines a cursor for table access
1414
</REFPURPOSE>
1515
<REFSYNOPSISDIV>
1616
<REFSYNOPSISDIVINFO>
17-
<DATE>1998-04-15</DATE>
17+
<DATE>1998-09-04</DATE>
1818
</REFSYNOPSISDIVINFO>
1919
<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> [, ...] ] ]
2223
</SYNOPSIS>
23-
<REFSECT2 ID="R2-SQL-DECLARESTATEMENT-1">
24+
<REFSECT2 ID="R2-SQL-DECLARE-1">
2425
<REFSECT2INFO>
2526
<DATE>1998-04-15</DATE>
2627
</REFSECT2INFO>
@@ -29,56 +30,117 @@
2930
</TITLE>
3031
<PARA>
3132
</PARA>
32-
<VARIABLELIST>
33-
<VARLISTENTRY>
34-
<TERM>
35-
</TERM>
36-
<LISTITEM>
37-
<PARA>
3833
<VARIABLELIST>
3934
<VARLISTENTRY>
4035
<TERM>
41-
<ReturnValue>BINARY</ReturnValue>
36+
<replaceable class="parameter">cursor</replaceable>
4237
</TERM>
4338
<LISTITEM>
4439
<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..
4741
</PARA>
4842
</LISTITEM>
4943
</VARLISTENTRY>
44+
5045
<VARLISTENTRY>
5146
<TERM>
52-
<ReturnValue><replaceable class="parameter">cursor</replaceable></ReturnValue>
47+
BINARY
5348
</TERM>
5449
<LISTITEM>
5550
<PARA>
56-
The cursor's name.
51+
Causes the cursor to fetch data in binary
52+
rather than in text format.
5753
</PARA>
5854
</LISTITEM>
5955
</VARLISTENTRY>
56+
6057
<VARLISTENTRY>
6158
<TERM>
62-
<ReturnValue><replaceable class="parameter">query</replaceable></ReturnValue>
59+
INSENSITIVE
6360
</TERM>
6461
<LISTITEM>
6562
<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.
6881
</PARA>
82+
</LISTITEM>
83+
</VARLISTENTRY>
84+
85+
<VARLISTENTRY>
86+
<TERM>
87+
<replaceable class="parameter">query</replaceable>
88+
</TERM>
89+
<LISTITEM>
6990
<PARA>
91+
An SQL query which will provide the rows to be governed by the
92+
cursor.
7093
Refer to the SELECT statement for further information about
7194
valid arguments.
7295
</PARA>
7396
</LISTITEM>
7497
</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+
78140
</VARIABLELIST>
79141
</REFSECT2>
80142

81-
<REFSECT2 ID="R2-SQL-DECLARESTATEMENT-2">
143+
<REFSECT2 ID="R2-SQL-DECLARE-2">
82144
<REFSECT2INFO>
83145
<DATE>1998-04-15</DATE>
84146
</REFSECT2INFO>
@@ -87,84 +149,105 @@
87149
</TITLE>
88150
<PARA>
89151
</PARA>
152+
90153
<VARIABLELIST>
91-
<VARLISTENTRY>
92-
<TERM>
93-
</TERM>
94-
<LISTITEM>
95-
<PARA>
96-
<VARIABLELIST>
97154
<VARLISTENTRY>
98155
<TERM>
99-
<ReturnValue>SELECT</ReturnValue>
156+
SELECT
100157
</TERM>
101158
<LISTITEM>
102159
<PARA>
103160
The message returned if the SELECT is run successfully.
104161
</PARA>
105162
</LISTITEM>
106163
</VARLISTENTRY>
164+
107165
<VARLISTENTRY>
108166
<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
111169
</TERM>
112170
<LISTITEM>
113171
<PARA>
114172
This error occurs if cursor "<replaceable class="parameter">cursor</replaceable>" is already declared.
115173
</PARA>
116174
</LISTITEM>
117175
</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+
121188
</VARIABLELIST>
122189
</REFSECT2>
123190
</REFSYNOPSISDIV>
124191

125-
<REFSECT1 ID="R1-SQL-DECLARESTATEMENT-1">
192+
<REFSECT1 ID="R1-SQL-DECLARE-1">
126193
<REFSECT1INFO>
127-
<DATE>1998-04-15</DATE>
194+
<DATE>1998-09-04</DATE>
128195
</REFSECT1INFO>
129196
<TITLE>
130197
Description
131198
</TITLE>
132199
<PARA>
133200
DECLARE allows a user to create cursors, which can be used to retrieve
134201
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.
136203
</PARA>
137204
<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
139208
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
144213
manipulate it anyway.
145214
</PARA>
146215
<PARA>
147216
BINARY cursors give you back the data in the native binary
148217
representation. So binary cursors will tend to be a
149218
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+
154232
<PARA>
155-
However,ASCII is architecture-neutral whereas binary
233+
However,string representation is architecture-neutral whereas binary
156234
representation can differ between different machine architectures.
157235
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
159238
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
161243
ASCII, getting it back in ASCII will save you some
162244
effort on the client side.
245+
</tip>
163246
</PARA>
164247

165-
<REFSECT2 ID="R2-SQL-DECLARESTATEMENT-3">
248+
<REFSECT2 ID="R2-SQL-DECLARE-3">
166249
<REFSECT2INFO>
167-
<DATE>1998-04-15</DATE>
250+
<DATE>1998-09-04</DATE>
168251
</REFSECT2INFO>
169252
<TITLE>
170253
Notes
@@ -173,8 +256,9 @@
173256
Cursors are only available in transactions.
174257
</PARA>
175258
<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.
178262
</PARA>
179263
</REFSECT2>
180264
</refsect1>
@@ -207,49 +291,14 @@
207291
SQL92
208292
</TITLE>
209293
<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+
253302
</REFENTRY>
254303

255304
<!-- Keep this comment at the end of the file

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp