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
This commit is contained in:
Tom Lane 2012-06-13 17:48:42 -04:00
parent 93f4d7f806
commit c3bc76bdb0
3 changed files with 42 additions and 13 deletions

View File

@ -163,7 +163,8 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
<para> <para>
Optionally, <literal>GLOBAL</literal> or <literal>LOCAL</literal> Optionally, <literal>GLOBAL</literal> or <literal>LOCAL</literal>
can be written before <literal>TEMPORARY</> or <literal>TEMP</>. can be written before <literal>TEMPORARY</> or <literal>TEMP</>.
This makes no difference in <productname>PostgreSQL</>, but see This presently makes no difference in <productname>PostgreSQL</>
and is deprecated; see
<xref linkend="sql-createtable-compatibility" <xref linkend="sql-createtable-compatibility"
endterm="sql-createtable-compatibility-title">. endterm="sql-createtable-compatibility-title">.
</para> </para>
@ -1304,13 +1305,20 @@ CREATE TABLE employees OF employee_type (
</para> </para>
<para> <para>
The standard's distinction between global and local temporary tables The SQL standard also distinguishes between global and local temporary
is not in <productname>PostgreSQL</productname>, since that distinction tables, where a local temporary table is only visible within a specific
depends on the concept of modules, which SQL module, though its definition is still shared across sessions. Since
<productname>PostgreSQL</productname> does not have. <productname>PostgreSQL</productname> does not support SQL modules, this
distinction is not relevant in <productname>PostgreSQL</productname>.
</para>
<para>
For compatibility's sake, <productname>PostgreSQL</productname> will For compatibility's sake, <productname>PostgreSQL</productname> will
accept the <literal>GLOBAL</literal> and <literal>LOCAL</literal> keywords accept the <literal>GLOBAL</literal> and <literal>LOCAL</literal> keywords
in a temporary table declaration, but they have no effect. in a temporary table declaration, but they currently have no effect.
Use of these keywords is discouraged, since future versions of
<productname>PostgreSQL</productname> might adopt a more
standard-compliant interpretation of their meaning.
</para> </para>
<para> <para>

View File

@ -62,9 +62,8 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE <replaceable
<term><literal>GLOBAL</literal> or <literal>LOCAL</literal></term> <term><literal>GLOBAL</literal> or <literal>LOCAL</literal></term>
<listitem> <listitem>
<para> <para>
Ignored for compatibility. Refer to <xref Ignored for compatibility. Use of these keywords is deprecated;
linkend="sql-createtable"> for refer to <xref linkend="sql-createtable"> for details.
details.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@ -2507,15 +2507,31 @@ CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
* Redundancy here is needed to avoid shift/reduce conflicts, * Redundancy here is needed to avoid shift/reduce conflicts,
* since TEMP is not a reserved word. See also OptTempTableName. * since TEMP is not a reserved word. See also OptTempTableName.
* *
* NOTE: we accept both GLOBAL and LOCAL options; since we have no modules * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
* the LOCAL keyword is really meaningless. * but future versions might consider GLOBAL to request SQL-spec-compliant
* temp table behavior, so warn about that. Since we have no modules the
* LOCAL keyword is really meaningless; furthermore, some other products
* implement LOCAL as meaning the same as our default temp table behavior,
* so we'll probably continue to treat LOCAL as a noise word.
*/ */
OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; } OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
| TEMP { $$ = RELPERSISTENCE_TEMP; } | TEMP { $$ = RELPERSISTENCE_TEMP; }
| LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; } | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
| LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; } | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
| GLOBAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; } | GLOBAL TEMPORARY
| GLOBAL TEMP { $$ = RELPERSISTENCE_TEMP; } {
ereport(WARNING,
(errmsg("GLOBAL is deprecated in temporary table creation"),
parser_errposition(@1)));
$$ = RELPERSISTENCE_TEMP;
}
| GLOBAL TEMP
{
ereport(WARNING,
(errmsg("GLOBAL is deprecated in temporary table creation"),
parser_errposition(@1)));
$$ = RELPERSISTENCE_TEMP;
}
| UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; } | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
| /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; } | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
; ;
@ -8930,11 +8946,17 @@ OptTempTableName:
} }
| GLOBAL TEMPORARY opt_table qualified_name | GLOBAL TEMPORARY opt_table qualified_name
{ {
ereport(WARNING,
(errmsg("GLOBAL is deprecated in temporary table creation"),
parser_errposition(@1)));
$$ = $4; $$ = $4;
$$->relpersistence = RELPERSISTENCE_TEMP; $$->relpersistence = RELPERSISTENCE_TEMP;
} }
| GLOBAL TEMP opt_table qualified_name | GLOBAL TEMP opt_table qualified_name
{ {
ereport(WARNING,
(errmsg("GLOBAL is deprecated in temporary table creation"),
parser_errposition(@1)));
$$ = $4; $$ = $4;
$$->relpersistence = RELPERSISTENCE_TEMP; $$->relpersistence = RELPERSISTENCE_TEMP;
} }