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

Commit c3bc76b

Browse files
committed
Deprecate use of GLOBAL and LOCAL in temp table creation.
Aside from adjusting the documentation to say that these are deprecated, we now report a warning (not an error) for use of GLOBAL, since it seems fairly likely that we might change that to request SQL-spec-compliant temp table behavior in the foreseeable future. Although our handling of LOCAL is equally nonstandard, there is no evident interest in ever implementing SQL modules, and furthermore some other products interpret LOCAL as behaving the same way we do. So no expectation of change and no warning for LOCAL; but it still seems a good idea to deprecate writing it. Noah Misch
1 parent 93f4d7f commit c3bc76b

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

doc/src/sgml/ref/create_table.sgml

+14-6
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
163163
<para>
164164
Optionally, <literal>GLOBAL</literal> or <literal>LOCAL</literal>
165165
can be written before <literal>TEMPORARY</> or <literal>TEMP</>.
166-
This makes no difference in <productname>PostgreSQL</>, but see
166+
This presently makes no difference in <productname>PostgreSQL</>
167+
and is deprecated; see
167168
<xref linkend="sql-createtable-compatibility"
168169
endterm="sql-createtable-compatibility-title">.
169170
</para>
@@ -1304,13 +1305,20 @@ CREATE TABLE employees OF employee_type (
13041305
</para>
13051306

13061307
<para>
1307-
The standard's distinction between global and local temporary tables
1308-
is not in <productname>PostgreSQL</productname>, since that distinction
1309-
depends on the concept of modules, which
1310-
<productname>PostgreSQL</productname> does not have.
1308+
The SQL standard also distinguishes between global and local temporary
1309+
tables, where a local temporary table is only visible within a specific
1310+
SQL module, though its definition is still shared across sessions. Since
1311+
<productname>PostgreSQL</productname> does not support SQL modules, this
1312+
distinction is not relevant in <productname>PostgreSQL</productname>.
1313+
</para>
1314+
1315+
<para>
13111316
For compatibility's sake, <productname>PostgreSQL</productname> will
13121317
accept the <literal>GLOBAL</literal> and <literal>LOCAL</literal> keywords
1313-
in a temporary table declaration, but they have no effect.
1318+
in a temporary table declaration, but they currently have no effect.
1319+
Use of these keywords is discouraged, since future versions of
1320+
<productname>PostgreSQL</productname> might adopt a more
1321+
standard-compliant interpretation of their meaning.
13141322
</para>
13151323

13161324
<para>

doc/src/sgml/ref/create_table_as.sgml

+2-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE <replaceable
6262
<term><literal>GLOBAL</literal> or <literal>LOCAL</literal></term>
6363
<listitem>
6464
<para>
65-
Ignored for compatibility. Refer to <xref
66-
linkend="sql-createtable"> for
67-
details.
65+
Ignored for compatibility. Use of these keywords is deprecated;
66+
refer to <xref linkend="sql-createtable"> for details.
6867
</para>
6968
</listitem>
7069
</varlistentry>

src/backend/parser/gram.y

+26-4
Original file line numberDiff line numberDiff line change
@@ -2507,15 +2507,31 @@ CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
25072507
* Redundancy here is needed to avoid shift/reduce conflicts,
25082508
* since TEMP is not a reserved word. See also OptTempTableName.
25092509
*
2510-
* NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2511-
* the LOCAL keyword is really meaningless.
2510+
* NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
2511+
* but future versions might consider GLOBAL to request SQL-spec-compliant
2512+
* temp table behavior, so warn about that. Since we have no modules the
2513+
* LOCAL keyword is really meaningless; furthermore, some other products
2514+
* implement LOCAL as meaning the same as our default temp table behavior,
2515+
* so we'll probably continue to treat LOCAL as a noise word.
25122516
*/
25132517
OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
25142518
| TEMP { $$ = RELPERSISTENCE_TEMP; }
25152519
| LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
25162520
| LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
2517-
| GLOBAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
2518-
| GLOBAL TEMP { $$ = RELPERSISTENCE_TEMP; }
2521+
| GLOBAL TEMPORARY
2522+
{
2523+
ereport(WARNING,
2524+
(errmsg("GLOBAL is deprecated in temporary table creation"),
2525+
parser_errposition(@1)));
2526+
$$ = RELPERSISTENCE_TEMP;
2527+
}
2528+
| GLOBAL TEMP
2529+
{
2530+
ereport(WARNING,
2531+
(errmsg("GLOBAL is deprecated in temporary table creation"),
2532+
parser_errposition(@1)));
2533+
$$ = RELPERSISTENCE_TEMP;
2534+
}
25192535
| UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
25202536
| /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
25212537
;
@@ -8930,11 +8946,17 @@ OptTempTableName:
89308946
}
89318947
| GLOBAL TEMPORARY opt_table qualified_name
89328948
{
8949+
ereport(WARNING,
8950+
(errmsg("GLOBAL is deprecated in temporary table creation"),
8951+
parser_errposition(@1)));
89338952
$$ = $4;
89348953
$$->relpersistence = RELPERSISTENCE_TEMP;
89358954
}
89368955
| GLOBAL TEMP opt_table qualified_name
89378956
{
8957+
ereport(WARNING,
8958+
(errmsg("GLOBAL is deprecated in temporary table creation"),
8959+
parser_errposition(@1)));
89388960
$$ = $4;
89398961
$$->relpersistence = RELPERSISTENCE_TEMP;
89408962
}

0 commit comments

Comments
 (0)