1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-05 23:38:41 +03:00

Implement "WITH / WITHOID OIDS" clause for CREATE TABLE AS. This is

intended to allow application authors to insulate themselves from
changes to the default value of 'default_with_oids' in future releases
of PostgreSQL.

This patch also fixes a bug in the earlier implementation of the
'default_with_oids' GUC variable: code in gram.y should not examine
the value of GUC variables directly due to synchronization issues.
This commit is contained in:
Neil Conway
2004-01-10 23:28:45 +00:00
parent cf4c925dd4
commit 98dcf085e3
14 changed files with 185 additions and 58 deletions

View File

@@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.19 2003/12/13 23:59:07 neilc Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.20 2004/01/10 23:28:44 neilc Exp $
PostgreSQL documentation
-->
@@ -20,7 +20,7 @@ PostgreSQL documentation
<refsynopsisdiv>
<synopsis>
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name</replaceable> [ (<replaceable>column_name</replaceable> [, ...] ) ]
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name</replaceable> [ (<replaceable>column_name</replaceable> [, ...] ) ] [ [ WITH | WITHOUT ] OIDS ]
AS <replaceable>query</replaceable>
</synopsis>
</refsynopsisdiv>
@@ -98,6 +98,20 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
</listitem>
</varlistentry>
<varlistentry>
<term><literal>WITH OIDS</literal></term>
<term><literal>WITHOUT OIDS</literal></term>
<listitem>
<para>
This optional clause specifies whether the table created by
<command>CREATE TABLE AS</command> should include OIDs. If
neither form of this clause if specified, the value of the
<varname>default_with_oids</varname> configuration parameter is
used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>query</replaceable></term>
<listitem>
@@ -121,23 +135,30 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
This command is functionally similar to <xref
linkend="sql-selectinto" endterm="sql-selectinto-title">, but it is
preferred since it is less likely to be confused with other uses of
the <command>SELECT INTO</command> syntax.
the <command>SELECT INTO</> syntax. Furthermore, <command>CREATE
TABLE AS</command> offers a superset of the functionality offerred
by <command>SELECT INTO</command>.
</para>
<para>
Prior to <productname>PostgreSQL</> 7.5, <command>CREATE TABLE
AS</command> always included OIDs in the table it
Prior to <productname>PostgreSQL</productname> 7.5, <command>CREATE
TABLE AS</command> always included OIDs in the table it
produced. Furthermore, these OIDs were newly generated: they were
distinct from the OIDs of any of the rows in the source tables of
the <command>SELECT</command> or <command>EXECUTE</command>
statement. Therefore, if <command>CREATE TABLE AS</command> was
frequently executed, the OID counter would be rapidly
incremented. As of <productname>PostgreSQL</> 7.5, the inclusion of
OIDs in the table generated by <command>CREATE TABLE AS</command>
is controlled by the <varname>default_with_oids</varname>
configuration variable. This variable currently defaults to true,
but will likely default to false in a future release of
<productname>PostgreSQL</>.
incremented. As of <productname>PostgresSQL</productname> 7.5,
the <command>CREATE TABLE AS</command> command allows the user to
explicitely specify whether OIDs should be included. If the
presence of OIDs is not explicitely specified,
the <varname>default_with_oids</varname> configuration variable is
used. While this variable currently defaults to true, the default
value may be changed in the future. Therefore, applications that
require OIDs in the table created by <command>CREATE TABLE
AS</command> should explicitely specify <literal>WITH
OIDS</literal> to ensure compatibility with future versions
of <productname>PostgreSQL</productname>.
</para>
</refsect1>

View File

@@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.229 2004/01/06 17:26:22 neilc Exp $
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.230 2004/01/10 23:28:43 neilc Exp $
-->
<Chapter Id="runtime">
@@ -2437,17 +2437,17 @@ dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
<term><varname>default_with_oids</varname> (<type>boolean</type>)</term>
<listitem>
<para>
This controls whether <command>CREATE TABLE</command> will
include OIDs in newly-created tables, if neither <literal>WITH
OIDS</literal> or <literal>WITHOUT OIDS</literal> have been
specified. It also determines whether OIDs will be included in
the table generated by <command>SELECT INTO</command> and
<command>CREATE TABLE AS</command>. In
This controls whether <command>CREATE TABLE</command>
and <command>CREATE TABLE AS</command> will include OIDs in
newly-created tables, if neither <literal>WITH OIDS</literal>
or <literal>WITHOUT OIDS</literal> have been specified. It
also determines whether OIDs will be included in the table
created by <command>SELECT INTO</command>. In
<productname>PostgreSQL</productname> &version;
<varname>default_with_oids</varname> defaults to true. This is
also the behavior of previous versions of
<productname>PostgreSQL</productname>. However, assuming that
tables will contain OIDs by default is not
<varname>default_with_oids</varname> defaults to
true. This is also the behavior of previous versions
of <productname>PostgreSQL</productname>. However, assuming
that tables will contain OIDs by default is not
encouraged. Therefore, this option will default to false in a
future release of <productname>PostgreSQL</productname>.
</para>