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

Commit7e1955b

Browse files
committed
docs: update PL/pgSQL docs about the use of := and =
1 parenta472ae1 commit7e1955b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

‎doc/src/sgml/plpgsql.sgml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ arow RECORD;
328328
<para>
329329
The general syntax of a variable declaration is:
330330
<synopsis>
331-
<replaceable>name</replaceable> <optional> CONSTANT </optional> <replaceable>type</replaceable> <optional> COLLATE <replaceable>collation_name</replaceable> </optional> <optional> NOT NULL </optional> <optional> { DEFAULT | := } <replaceable>expression</replaceable> </optional>;
331+
<replaceable>name</replaceable> <optional> CONSTANT </optional> <replaceable>type</replaceable> <optional> COLLATE <replaceable>collation_name</replaceable> </optional> <optional> NOT NULL </optional> <optional> { DEFAULT | :=| =} <replaceable>expression</replaceable> </optional>;
332332
</synopsis>
333333
The <literal>DEFAULT</> clause, if given, specifies the initial value assigned
334334
to the variable when the block is entered. If the <literal>DEFAULT</> clause
@@ -343,6 +343,8 @@ arow RECORD;
343343
is specified, an assignment of a null value results in a run-time
344344
error. All variables declared as <literal>NOT NULL</>
345345
must have a nonnull default value specified.
346+
Equals (<literal>=</>) can be used instead of PL/SQL-compliant
347+
<literal>:=</>.
346348
</para>
347349

348350
<para>
@@ -866,15 +868,16 @@ PREPARE <replaceable>statement_name</>(integer, integer) AS SELECT $1 &lt; $2;
866868
An assignment of a value to a <application>PL/pgSQL</application>
867869
variable is written as:
868870
<synopsis>
869-
<replaceable>variable</replaceable>:= <replaceable>expression</replaceable>;
871+
<replaceable>variable</replaceable>{ := | = } <replaceable>expression</replaceable>;
870872
</synopsis>
871873
As explained previously, the expression in such a statement is evaluated
872874
by means of an SQL <command>SELECT</> command sent to the main
873875
database engine. The expression must yield a single value (possibly
874876
a row value, if the variable is a row or record variable). The target
875877
variable can be a simple variable (optionally qualified with a block
876878
name), a field of a row or record variable, or an element of an array
877-
that is a simple variable or field.
879+
that is a simple variable or field. Equals (<literal>=</>) can be
880+
used instead of PL/SQL-compliant <literal>:=</>.
878881
</para>
879882

880883
<para>
@@ -1411,7 +1414,7 @@ EXECUTE format('UPDATE tbl SET %I = $1 WHERE key = $2', colname)
14111414
command, which has the form:
14121415

14131416
<synopsis>
1414-
GET <optional> CURRENT </optional> DIAGNOSTICS <replaceable>variable</replaceable>= <replaceable>item</replaceable> <optional> , ... </optional>;
1417+
GET <optional> CURRENT </optional> DIAGNOSTICS <replaceable>variable</replaceable>{ = | := } <replaceable>item</replaceable> <optional> , ... </optional>;
14151418
</synopsis>
14161419

14171420
This command allows retrieval of system status indicators. Each
@@ -1425,6 +1428,8 @@ GET <optional> CURRENT </optional> DIAGNOSTICS <replaceable>variable</replaceabl
14251428
<acronym>SQL</acronym> command. Note that <varname>RESULT_OID</>
14261429
is only useful after an <command>INSERT</command> command into a
14271430
table containing OIDs.
1431+
Equals (<literal>:=</>) can be used instead of SQL-standard
1432+
<literal>=</> for <command>GET DIAGNOSTICS</>.
14281433
</para>
14291434

14301435
<para>
@@ -2672,7 +2677,7 @@ SELECT merge_db(1, 'dennis');
26722677
<command>GET STACKED DIAGNOSTICS</command> command, which has the form:
26732678

26742679
<synopsis>
2675-
GET STACKED DIAGNOSTICS <replaceable>variable</replaceable>= <replaceable>item</replaceable> <optional> , ... </optional>;
2680+
GET STACKED DIAGNOSTICS <replaceable>variable</replaceable>{ = | := } <replaceable>item</replaceable> <optional> , ... </optional>;
26762681
</synopsis>
26772682

26782683
Each <replaceable>item</replaceable> is a key word identifying a status
@@ -2776,7 +2781,7 @@ END;
27762781
<para>
27772782

27782783
<synopsis>
2779-
GET <optional> CURRENT </optional> DIAGNOSTICS <replaceable>variable</replaceable>= <replaceable>PG_CONTEXT</replaceable> <optional> , ... </optional>;
2784+
GET <optional> CURRENT </optional> DIAGNOSTICS <replaceable>variable</replaceable>{ = | := } <replaceable>PG_CONTEXT</replaceable> <optional> , ... </optional>;
27802785
</synopsis>
27812786

27822787

‎src/pl/plpgsql/src/pl_gram.y

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,12 @@ decl_defkey: assign_operator
796796
| K_DEFAULT
797797
;
798798

799-
assign_operator:'='/* not documented because it might be removed someday*/
799+
/*
800+
* Ada-based PL/SQL uses := for assignment and variable defaults, while
801+
* the SQL standard uses equals for these cases and for GET
802+
* DIAGNOSTICS, so we support both. FOR and OPEN only support :=.
803+
*/
804+
assign_operator:'='
800805
| COLON_EQUALS
801806
;
802807

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp