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

Commit6077db9

Browse files
committed
Allow FOR UPDATE to appear after LIMIT/OFFSET to match MySQL syntax and as
a more logical ordering.
1 parent8e4357d commit6077db9

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

‎doc/src/sgml/ref/select.sgml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.56 2002/08/15 02:59:18 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.57 2002/08/28 14:35:37 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -28,9 +28,9 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replac
2828
[ HAVING <replaceable class="PARAMETER">condition</replaceable> [, ...] ]
2929
[ { UNION | INTERSECT | EXCEPT } [ ALL ] <replaceable class="PARAMETER">select</replaceable> ]
3030
[ ORDER BY <replaceable class="PARAMETER">expression</replaceable> [ ASC | DESC | USING <replaceable class="PARAMETER">operator</replaceable> ] [, ...] ]
31-
[ FOR UPDATE [ OF <replaceable class="PARAMETER">tablename</replaceable> [, ...] ] ]
3231
[ LIMIT { <replaceable class="PARAMETER">count</replaceable> | ALL } ]
3332
[ OFFSET <replaceable class="PARAMETER">start</replaceable> ]
33+
[ FOR UPDATE [ OF <replaceable class="PARAMETER">tablename</replaceable> [, ...] ] ]
3434

3535
where <replaceable class="PARAMETER">from_item</replaceable> can be:
3636

@@ -107,9 +107,9 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
107107
<term><replaceable class="PARAMETER">select</replaceable></term>
108108
<listitem>
109109
<para>
110-
A select statement with all features except the ORDER BY,FOR UPDATE,
111-
andLIMITclauses (even those can be used when theselect is
112-
parenthesized).
110+
A select statement with all features except the ORDER BY,
111+
LIMIT/OFFSET,andFOR UPDATEclauses (even those can be used when the
112+
select isparenthesized).
113113
</para>
114114
</listitem>
115115
</varlistentry>
@@ -354,17 +354,17 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
354354
(See <xref linkend="sql-except" endterm="sql-except-title">.)
355355
</para>
356356

357-
<para>
358-
The FOR UPDATE clause allows the SELECT statement to perform
359-
exclusive locking of selected rows.
360-
</para>
361-
362357
<para>
363358
The LIMIT clause allows a subset of the rows produced by the query
364359
to be returned to the user.
365360
(See <xref linkend="sql-limit" endterm="sql-limit-title">.)
366361
</para>
367362

363+
<para>
364+
The FOR UPDATE clause allows the SELECT statement to perform
365+
exclusive locking of selected rows.
366+
</para>
367+
368368
<para>
369369
You must have SELECT privilege to a table to read its values
370370
(See the <command>GRANT</command>/<command>REVOKE</command> statements).
@@ -666,8 +666,8 @@ SELECT name FROM distributors ORDER BY code;
666666

667667
where
668668
<replaceable class="PARAMETER">table_query</replaceable>
669-
specifies any select expression without an ORDER BY, FOR UPDATE,
670-
or LIMITclause. (ORDER BY and LIMIT can be attached to a sub-expression
669+
specifies any select expression without an ORDER BY,LIMIT, orFOR UPDATE
670+
clause. (ORDER BY and LIMIT can be attached to a sub-expression
671671
if it is enclosed in parentheses. Without parentheses, these clauses
672672
will be taken to apply to the result of the UNION, not to its right-hand
673673
input expression.)
@@ -716,8 +716,8 @@ SELECT name FROM distributors ORDER BY code;
716716

717717
where
718718
<replaceable class="PARAMETER">table_query</replaceable>
719-
specifies any select expression without an ORDER BY,FOR UPDATE,
720-
or LIMIT clause.
719+
specifies any select expression without an ORDER BY,LIMIT, or
720+
FOR UPDATE clause.
721721
</para>
722722

723723
<para>
@@ -757,8 +757,8 @@ SELECT name FROM distributors ORDER BY code;
757757

758758
where
759759
<replaceable class="PARAMETER">table_query</replaceable>
760-
specifies any select expression without an ORDER BY,FOR UPDATE,
761-
orLIMIT clause.
760+
specifies any select expression without an ORDER BY,LIMIT,
761+
orFOR UPDATE clause.
762762
</para>
763763

764764
<para>

‎doc/src/sgml/ref/select_into.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select_into.sgml,v 1.18 2002/04/23 02:07:16 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select_into.sgml,v 1.19 2002/08/28 14:35:37 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -29,9 +29,9 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replac
2929
[ HAVING <replaceable class="PARAMETER">condition</replaceable> [, ...] ]
3030
[ { UNION | INTERSECT | EXCEPT } [ ALL ] <replaceable class="PARAMETER">select</replaceable> ]
3131
[ ORDER BY <replaceable class="PARAMETER">expression</replaceable> [ ASC | DESC | USING <replaceable class="PARAMETER">operator</replaceable> ] [, ...] ]
32-
[ FOR UPDATE [ OF <replaceable class="PARAMETER">tablename</replaceable> [, ...] ] ]
3332
[ LIMIT [ <replaceable class="PARAMETER">start</replaceable> , ] { <replaceable class="PARAMETER">count</replaceable> | ALL } ]
3433
[ OFFSET <replaceable class="PARAMETER">start</replaceable> ]
34+
[ FOR UPDATE [ OF <replaceable class="PARAMETER">tablename</replaceable> [, ...] ] ]
3535

3636
where <replaceable class="PARAMETER">from_item</replaceable> can be:
3737

‎doc/src/sgml/sql.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.26 2002/03/15 16:16:31 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.27 2002/08/28 14:35:36 momjian Exp $
33
-->
44

55
<chapter id="sql">
@@ -863,9 +863,9 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replac
863863
[ HAVING <replaceable class="PARAMETER">condition</replaceable> [, ...] ]
864864
[ { UNION | INTERSECT | EXCEPT } [ ALL ] <replaceable class="PARAMETER">select</replaceable> ]
865865
[ ORDER BY <replaceable class="PARAMETER">expression</replaceable> [ ASC | DESC | USING <replaceable class="PARAMETER">operator</replaceable> ] [, ...] ]
866-
[ FOR UPDATE [ OF <replaceable class="PARAMETER">class_name</replaceable> [, ...] ] ]
867866
[ LIMIT { <replaceable class="PARAMETER">count</replaceable> | ALL } ]
868867
[ OFFSET <replaceable class="PARAMETER">start</replaceable> ]
868+
[ FOR UPDATE [ OF <replaceable class="PARAMETER">class_name</replaceable> [, ...] ] ]
869869
</synopsis>
870870
</para>
871871

‎src/backend/parser/gram.y

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.361 2002/08/27 04:55:08 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.362 2002/08/28 14:35:37 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -208,8 +208,8 @@ static void doNegateFloat(Value *v);
208208
func_args_list,func_as,createfunc_opt_list
209209
oper_argtypes,RuleActionList,RuleActionMulti,
210210
opt_column_list,columnList,opt_name_list,
211-
sort_clause,sortby_list,index_params,index_list,
212-
name_list,from_clause,from_list,opt_array_bounds,
211+
sort_clause,opt_sort_clause,sortby_list,index_params,
212+
index_list,name_list,from_clause,from_list,opt_array_bounds,
213213
qualified_name_list,any_name,any_name_list,
214214
any_operator,expr_list,dotted_name,attrs,
215215
target_list,update_target_list,insert_column_list,
@@ -4180,24 +4180,30 @@ select_with_parens:
41804180
|'(' select_with_parens')'{$$ =$2; }
41814181
;
41824182

4183+
/*
4184+
*FOR UPDATE may be before or after LIMIT/OFFSET.
4185+
*In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
4186+
*We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE
4187+
*2002-08-28 bjm
4188+
*/
41834189
select_no_parens:
41844190
simple_select{$$ =$1; }
4185-
| select_clause sort_clause opt_for_update_clause opt_select_limit
4191+
| select_clause sort_clause
41864192
{
4187-
insertSelectOptions((SelectStmt *) $1, $2,$3,
4188-
nth(0, $4), nth(1, $4));
4193+
insertSelectOptions((SelectStmt *) $1, $2,NIL,
4194+
NULL, NULL);
41894195
$$ =$1;
41904196
}
4191-
| select_clause for_update_clause opt_select_limit
4197+
| select_clauseopt_sort_clausefor_update_clause opt_select_limit
41924198
{
4193-
insertSelectOptions((SelectStmt *) $1,NIL, $2,
4194-
nth(0, $3), nth(1, $3));
4199+
insertSelectOptions((SelectStmt *) $1,$2, $3,
4200+
nth(0, $4), nth(1, $4));
41954201
$$ =$1;
41964202
}
4197-
| select_clause select_limit
4203+
| select_clauseopt_sort_clauseselect_limit opt_for_update_clause
41984204
{
4199-
insertSelectOptions((SelectStmt *) $1,NIL, NIL,
4200-
nth(0, $2), nth(1, $2));
4205+
insertSelectOptions((SelectStmt *) $1,$2, $4,
4206+
nth(0, $3), nth(1, $3));
42014207
$$ =$1;
42024208
}
42034209
;
@@ -4335,6 +4341,11 @@ opt_distinct:
43354341
|/*EMPTY*/{$$ = NIL; }
43364342
;
43374343

4344+
opt_sort_clause:
4345+
sort_clause{$$ =$1;}
4346+
|/*EMPTY*/{$$ = NIL; }
4347+
;
4348+
43384349
sort_clause:
43394350
ORDER BY sortby_list{$$ =$3; }
43404351
;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp