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

Commit 7f7e8cc

Browse files
committed
Allow commas in BEGIN, START TRANSACTION, and SET TRANSACTION, as required
by the SQL standard. For backwards compatibility, however, continue to accept the syntax without. Minor editorialization in the reference pages for these commands, too.
1 parent 9e01aaa commit 7f7e8cc

File tree

5 files changed

+140
-96
lines changed

5 files changed

+140
-96
lines changed

doc/src/sgml/ref/begin.sgml

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/begin.sgml,v 1.32 2004/08/08 01:48:31 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/begin.sgml,v 1.33 2004/08/12 21:00:21 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -20,9 +20,12 @@ PostgreSQL documentation
2020

2121
<refsynopsisdiv>
2222
<synopsis>
23-
BEGIN [ WORK | TRANSACTION ]
24-
[ ISOLATION LEVEL { READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE } ]
25-
[ READ WRITE | READ ONLY ]
23+
BEGIN [ WORK | TRANSACTION ] [ <replaceable class="parameter">transaction_mode</replaceable> [, ...] ]
24+
25+
where <replaceable class="parameter">transaction_mode</replaceable> is one of:
26+
27+
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
28+
READ WRITE | READ ONLY
2629
</synopsis>
2730
</refsynopsisdiv>
2831

@@ -101,8 +104,13 @@ BEGIN [ WORK | TRANSACTION ]
101104
Issuing <command>BEGIN</> when already inside a transaction block will
102105
provoke a warning message. The state of the transaction is not affected.
103106
To nest transactions within a transaction block, use savepoints
104-
(See <xref linkend="sql-start-transaction" endterm="sql-start-transaction-title">
105-
for more information).
107+
(see <xref linkend="sql-savepoint" endterm="sql-savepoint-title">).
108+
</para>
109+
110+
<para>
111+
For reasons of backwards compatibility, the commas between successive
112+
<replaceable class="parameter">transaction_modes</replaceable> may be
113+
omitted.
106114
</para>
107115
</refsect1>
108116

@@ -123,15 +131,10 @@ BEGIN;
123131

124132
<para>
125133
<command>BEGIN</command> is a <productname>PostgreSQL</productname>
126-
language extension. There is no explicit <command>BEGIN</command>
127-
command in the SQL standard; transaction initiation is
128-
always implicit and it terminates either with a
129-
<command>COMMIT</command> or <command>ROLLBACK</command> statement.
130-
</para>
131-
132-
<para>
133-
Other relational database systems may offer an autocommit feature
134-
as a convenience.
134+
language extension. It is equivalent to the SQL-standard command
135+
<xref linkend="sql-start-transaction"
136+
endterm="sql-start-transaction-title">, which see for additional
137+
compatibility information.
135138
</para>
136139

137140
<para>

doc/src/sgml/ref/set_transaction.sgml

+56-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/set_transaction.sgml,v 1.19 2003/11/29 19:51:39 pgsql Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/set_transaction.sgml,v 1.20 2004/08/12 21:00:22 tgl Exp $ -->
22
<refentry id="SQL-SET-TRANSACTION">
33
<refmeta>
44
<refentrytitle id="SQL-SET-TRANSACTION-TITLE">SET TRANSACTION</refentrytitle>
@@ -16,13 +16,13 @@
1616

1717
<refsynopsisdiv>
1818
<synopsis>
19-
SET TRANSACTION
20-
[ ISOLATION LEVEL { READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE } ]
21-
[ READ WRITE | READ ONLY ]
19+
SET TRANSACTION <replaceable class="parameter">transaction_mode</replaceable> [, ...]
20+
SET SESSION CHARACTERISTICS AS TRANSACTION <replaceable class="parameter">transaction_mode</replaceable> [, ...]
2221

23-
SET SESSION CHARACTERISTICS AS TRANSACTION
24-
[ ISOLATION LEVEL { READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE } ]
25-
[ READ WRITE | READ ONLY ]
22+
where <replaceable class="parameter">transaction_mode</replaceable> is one of:
23+
24+
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
25+
READ WRITE | READ ONLY
2626
</synopsis>
2727
</refsynopsisdiv>
2828

@@ -34,7 +34,7 @@ SET SESSION CHARACTERISTICS AS TRANSACTION
3434
characteristics of the current transaction. It has no effect on any
3535
subsequent transactions. <command>SET SESSION
3636
CHARACTERISTICS</command> sets the default transaction
37-
characteristics for each transaction of a session. <command>SET
37+
characteristics for subsequent transactions of a session. <command>SET
3838
TRANSACTION</command> can override it for an individual
3939
transaction.
4040
</para>
@@ -47,7 +47,7 @@ SET SESSION CHARACTERISTICS AS TRANSACTION
4747

4848
<para>
4949
The isolation level of a transaction determines what data the
50-
transaction can see when other transactions are running concurrently.
50+
transaction can see when other transactions are running concurrently:
5151

5252
<variablelist>
5353
<varlistentry>
@@ -64,28 +64,35 @@ SET SESSION CHARACTERISTICS AS TRANSACTION
6464
<term><literal>SERIALIZABLE</literal></term>
6565
<listitem>
6666
<para>
67-
The current transaction can only see rows committed before
68-
first query or data-modification statement was executed in this transaction.
67+
All statements of the current transaction can only see rows committed
68+
before the first query or data-modification statement was executed in
69+
this transaction.
6970
</para>
7071
<tip>
7172
<para>
7273
Intuitively, serializable means that two concurrent
7374
transactions will leave the database in the same state as if
74-
the two has been executed strictly after one another in either
75-
order.
75+
the two had been executed strictly one after the other (in one
76+
order or the other).
7677
</para>
7778
</tip>
7879
</listitem>
7980
</varlistentry>
8081
</variablelist>
8182

82-
The level <literal>READ UNCOMMITTED</literal> is mapped to
83-
<literal>READ COMMITTED</literal>, the level <literal>REPEATABLE
84-
READ</literal> is mapped to <literal>SERIALIZABLE</literal>, The
85-
transaction isolation level cannot be set after the first query or
83+
The SQL standard defines two additional levels, <literal>READ
84+
UNCOMMITTED</literal> and <literal>REPEATABLE READ</literal>.
85+
In <productname>PostgreSQL</productname> <literal>READ
86+
UNCOMMITTED</literal> is treated as
87+
<literal>READ COMMITTED</literal>, while <literal>REPEATABLE
88+
READ</literal> is treated as <literal>SERIALIZABLE</literal>.
89+
</para>
90+
91+
<para>
92+
The transaction isolation level cannot be changed after the first query or
8693
data-modification statement (<command>SELECT</command>,
8794
<command>INSERT</command>, <command>DELETE</command>,
88-
<command>UPDATE</command>, <command>FETCH</command>,
95+
<command>UPDATE</command>, <command>FETCH</command>, or
8996
<command>COPY</command>) of a transaction has been executed. See
9097
<xref linkend="mvcc"> for more information about transaction
9198
isolation and concurrency control.
@@ -112,13 +119,27 @@ SET SESSION CHARACTERISTICS AS TRANSACTION
112119
<title>Notes</title>
113120

114121
<para>
115-
The session default transaction isolation level can also be set
116-
with the command
117-
<programlisting>
118-
SET default_transaction_isolation = '<replaceable>value</replaceable>'
119-
</programlisting>
120-
and in the configuration file. Consult <xref linkend="runtime-config"> for more
121-
information.
122+
If <command>SET TRANSACTION</command> is executed without a prior
123+
<command>START TRANSACTION</command> or <command>BEGIN</command>,
124+
it will appear to have no effect, since the transaction will immediately
125+
end.
126+
</para>
127+
128+
<para>
129+
It is possible to dispense with <command>SET TRANSACTION</command> by
130+
instead specifying the desired <replaceable
131+
class="parameter">transaction_modes</replaceable> in
132+
<command>START TRANSACTION</command>.
133+
</para>
134+
135+
<para>
136+
The session default transaction modes can also be set by setting the
137+
configuration parameters <xref linkend="guc-default-transaction-isolation">
138+
and <xref linkend="guc-default-transaction-read-only">.
139+
(In fact <command>SET SESSION CHARACTERISTICS</command> is just a
140+
verbose equivalent for setting these variables with <command>SET</>.)
141+
This allows them to be set in the configuration file. Consult <xref
142+
linkend="runtime-config"> for more information.
122143
</para>
123144
</refsect1>
124145

@@ -131,15 +152,23 @@ SET default_transaction_isolation = '<replaceable>value</replaceable>'
131152
isolation level in the standard; in
132153
<productname>PostgreSQL</productname> the default is ordinarily
133154
<literal>READ COMMITTED</literal>, but you can change it as
134-
described above. Because of multiversion concurrency control, the
155+
mentioned above. Because of multiversion concurrency control, the
135156
<literal>SERIALIZABLE</literal> level is not truly
136157
serializable. See <xref linkend="mvcc"> for details.
137158
</para>
138159

139160
<para>
140161
In the SQL standard, there is one other transaction characteristic
141162
that can be set with these commands: the size of the diagnostics
142-
area. This concept is only for use in embedded SQL.
163+
area. This concept is specific to embedded SQL, and therefore is
164+
not implemented in the <productname>PostgreSQL</productname> server.
165+
</para>
166+
167+
<para>
168+
The SQL standard requires commas between successive <replaceable
169+
class="parameter">transaction_modes</replaceable>, but for historical
170+
reasons <productname>PostgreSQL</productname> allows the commas to be
171+
omitted.
143172
</para>
144173
</refsect1>
145174
</refentry>

doc/src/sgml/ref/start_transaction.sgml

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/start_transaction.sgml,v 1.12 2004/08/01 17:32:13 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/start_transaction.sgml,v 1.13 2004/08/12 21:00:23 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -20,20 +20,23 @@ PostgreSQL documentation
2020

2121
<refsynopsisdiv>
2222
<synopsis>
23-
START TRANSACTION
24-
[ ISOLATION LEVEL { READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE } ]
25-
[ READ WRITE | READ ONLY ]
23+
START TRANSACTION [ <replaceable class="parameter">transaction_mode</replaceable> [, ...] ]
24+
25+
where <replaceable class="parameter">transaction_mode</replaceable> is one of:
26+
27+
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
28+
READ WRITE | READ ONLY
2629
</synopsis>
2730
</refsynopsisdiv>
2831

2932
<refsect1>
3033
<title>Description</title>
3134

3235
<para>
33-
This command begins a new transaction. If the isolation level or
36+
This command begins a new transaction block. If the isolation level or
3437
read/write mode is specified, the new transaction has those
3538
characteristics, as if <xref linkend="sql-set-transaction"
36-
endterm="sql-set-transaction-title"> was executed. It is the same
39+
endterm="sql-set-transaction-title"> was executed. This is the same
3740
as the <xref linkend="sql-begin" endterm="sql-begin-title"> command.
3841
</para>
3942
</refsect1>
@@ -52,8 +55,25 @@ START TRANSACTION
5255
<title>Compatibility</title>
5356

5457
<para>
55-
This command conforms to the SQL standard; but see also the
56-
compatibility section of <xref linkend="sql-set-transaction"
58+
In the standard, it is not necessary to issue <command>START TRANSACTION</>
59+
to start a transaction block: any SQL command implicitly begins a block.
60+
<productname>PostgreSQL</productname>'s behavior can be seen as implicitly
61+
issuing a <command>COMMIT</command> after each command that does not
62+
follow <command>START TRANSACTION</> (or <command>BEGIN</command>),
63+
and it is therefore often called <quote>autocommit</>.
64+
Other relational database systems may offer an autocommit feature
65+
as a convenience.
66+
</para>
67+
68+
<para>
69+
The SQL standard requires commas between successive <replaceable
70+
class="parameter">transaction_modes</replaceable>, but for historical
71+
reasons <productname>PostgreSQL</productname> allows the commas to be
72+
omitted.
73+
</para>
74+
75+
<para>
76+
See also the compatibility section of <xref linkend="sql-set-transaction"
5777
endterm="sql-set-transaction-title">.
5878
</para>
5979
</refsect1>

src/backend/parser/gram.y

+24-30
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.470 2004/08/12 19:12:21 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.471 2004/08/12 21:00:28 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -161,11 +161,11 @@ static void doNegateFloat(Value *v);
161161

162162
%type <dbehavior> opt_drop_behavior
163163

164-
%type <list> createdb_opt_list copy_opt_list
165-
%type <defelt> createdb_opt_item copy_opt_item
164+
%type <list> createdb_opt_list copy_opt_list transaction_mode_list
165+
%type <defelt> createdb_opt_item copy_opt_item transaction_mode_item
166166

167167
%type <ival> opt_lock lock_type cast_context
168-
%type <boolean> opt_force opt_or_replace transaction_access_mode
168+
%type <boolean> opt_force opt_or_replace
169169
opt_grant_grant_option opt_revoke_grant_option
170170
opt_nowait
171171

@@ -222,7 +222,7 @@ static void doNegateFloat(Value *v);
222222
target_list update_target_list insert_column_list
223223
insert_target_list def_list indirection opt_indirection
224224
group_clause TriggerFuncArgs select_limit
225-
opt_select_limit opclass_item_list transaction_mode_list
225+
opt_select_limit opclass_item_list
226226
transaction_mode_list_or_empty
227227
TableFuncElementList
228228
prep_type_clause prep_type_list
@@ -4021,27 +4021,26 @@ opt_transaction: WORK {}
40214021
| /*EMPTY*/ {}
40224022
;
40234023

4024-
transaction_mode_list:
4024+
transaction_mode_item:
40254025
ISOLATION LEVEL iso_level
4026-
{ $$ = list_make1(makeDefElem("transaction_isolation",
4027-
makeStringConst($3, NULL))); }
4028-
| transaction_access_mode
4029-
{ $$ = list_make1(makeDefElem("transaction_read_only",
4030-
makeIntConst($1))); }
4031-
| ISOLATION LEVEL iso_level transaction_access_mode
4032-
{
4033-
$$ = list_make2(makeDefElem("transaction_isolation",
4034-
makeStringConst($3, NULL)),
4035-
makeDefElem("transaction_read_only",
4036-
makeIntConst($4)));
4037-
}
4038-
| transaction_access_mode ISOLATION LEVEL iso_level
4039-
{
4040-
$$ = list_make2(makeDefElem("transaction_read_only",
4041-
makeIntConst($1)),
4042-
makeDefElem("transaction_isolation",
4043-
makeStringConst($4, NULL)));
4044-
}
4026+
{ $$ = makeDefElem("transaction_isolation",
4027+
makeStringConst($3, NULL)); }
4028+
| READ ONLY
4029+
{ $$ = makeDefElem("transaction_read_only",
4030+
makeIntConst(TRUE)); }
4031+
| READ WRITE
4032+
{ $$ = makeDefElem("transaction_read_only",
4033+
makeIntConst(FALSE)); }
4034+
;
4035+
4036+
/* Syntax with commas is SQL-spec, without commas is Postgres historical */
4037+
transaction_mode_list:
4038+
transaction_mode_item
4039+
{ $$ = list_make1($1); }
4040+
| transaction_mode_list ',' transaction_mode_item
4041+
{ $$ = lappend($1, $3); }
4042+
| transaction_mode_list transaction_mode_item
4043+
{ $$ = lappend($1, $2); }
40454044
;
40464045

40474046
transaction_mode_list_or_empty:
@@ -4050,11 +4049,6 @@ transaction_mode_list_or_empty:
40504049
{ $$ = NIL; }
40514050
;
40524051

4053-
transaction_access_mode:
4054-
READ ONLY { $$ = TRUE; }
4055-
| READ WRITE { $$ = FALSE; }
4056-
;
4057-
40584052

40594053
/*****************************************************************************
40604054
*

0 commit comments

Comments
 (0)