- linkend="sql-selectinto" endterm="sql-selectinto-title">, but it is preferred since it is less
- ... INTO syntax.
- Prepared statements are only stored in and for the duration of
- the current database session. When
- the session ends, the prepared statement is forgotten, and so it must be
- recreated before being used again. This also means that a single
- prepared statement cannot be used by multiple simultaneous database
- clients; however, each client can create their own prepared statement
- to use.
+ Prepared statements are only for the duration of the current
+ database session. When the session ends, the prepared statement is
+ forgotten, so it must be recreated before being used again. This
+ also means that a single prepared statement cannot be used by
+ multiple simultaneous database clients; however, each client can
+ create their own prepared statement to use.
Notes
-
- is functionally equivalent to SELECT INTO.
- CREATE TABLE AS is the recommended syntax, since
- this form of SELECT INTO is not available in
-
PL/pgSQL, because they interpret the
- INTO clause differently.
+
+ endterm="sql-createtableas-title"> is functionally similar to
+ SELECT INTO. CREATE TABLE AS
+ is the recommended syntax, since this form of SELECT
+ INTO is not available in
ECPG
+ or
PL/pgSQL, because they interpret the
+ INTO clause differently. Furthermore,
+ CREATE TABLE AS offers a superset of the
+ functionality provided by SELECT INTO.
+
+
+ Prior to PostgreSQL 7.5, the table created by SELECT
+ INTO always included OIDs. Furthermore, these OIDs were
+ newly generated: they were distinct from the OIDs of any of the
+ rows in the source tables of the SELECT INTO
+ statement. Therefore, if SELECT INTO was
+ frequently executed, the OID counter would be rapidly
+ incremented. As of PostgreSQL 7.5, the inclusion of OIDs in the
+ table created by SELECT INTO is controlled by
+ the default_with_oids configuration
+ variable. This variable currently defaults to true, but will likely
+ default to false in a future release of
PostgreSQL>.
Compatibility
- The SQL standard uses SELECT ... INTO to
+ The SQL standard uses SELECT INTO to
represent selecting values into scalar variables of a host program,
rather than creating a new table. This indeed is the usage found
-
+
+ default_with_oids (boolean)
+
+ This controls whether CREATE TABLE will
+ include OIDs in newly-created tables, if neither WITH
+ OIDS or WITHOUT OIDS have been
+ specified. It also determines whether OIDs will be included in
+ the table generated by SELECT INTO and
+ CREATE TABLE AS. In
+ default_with_oids defaults to true. This is
+ also the behavior of previous versions of
+
PostgreSQL. However, assuming that
+ tables will contain OIDs by default is not
+ encouraged. Therefore, this option will default to false in a
+ future release of
PostgreSQL.
+
+
+ To ease compatibility with applications that make use of OIDs,
+ this option should left enabled. To ease compatibility with
+ future versions of
PostgreSQL, this
+ option should be disabled, and applications that require OIDs
+ on certain tables should explictely specify WITH
+ OIDS when issuing the CREATE
+ TABLE statements for the tables in question.
+
+
+
+
+
Platform and Client Compatibility
if a SELECT (but not SELECT
- ... INTO>) was executed
+ INTO>) was executed
SPI_OK_SELINTO
- if a SELECT ... INTO was executed
+ if a SELECT INTO was executed
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.222 2003/11/29 19:51:48 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.223 2003/12/01 22:07:58 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "optimizer/var.h"
#include "parser/parsetree.h"
#include "utils/acl.h"
+#include "utils/guc.h"
#include "utils/lsyscache.h"
do_select_into = true;
/*
- * For now, always create OIDs in SELECT INTO; this is for
- * backwards compatibility with pre-7.3 behavior. Eventually we
- * might want to allow the user to choose.
+ * The presence of OIDs in the result set of SELECT INTO is
+ * controlled by the default_with_oids GUC parameter. The
+ * behavior in versions of PostgreSQL prior to 7.5 is to
+ * always include OIDs.
*/
- estate->es_force_oids = true;
+ estate->es_force_oids = default_with_oids;
}
/*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.440 2003/11/29 19:51:51 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.441 2003/12/01 22:07:58 momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
#include "utils/numeric.h"
#include "utils/datetime.h"
#include "utils/date.h"
+#include "utils/guc.h"
extern List *parsetree; /* final parse result is delivered here */
OptWithOids:
WITH OIDS { $$ = TRUE; }
| WITHOUT OIDS { $$ = FALSE; }
- | /*EMPTY*/ { $$ = TRUE; }
+ /*
+ * If the user didn't explicitely specify WITH or WITHOUT
+ * OIDS, decide whether to include OIDs based on the
+ * "default_with_oids" GUC var
+ */
+ | /*EMPTY*/ { $$ = default_with_oids; }
;
OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
* Written by Peter Eisentraut
.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.173 2003/12/01 03:55:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.174 2003/12/01 22:08:00 momjian Exp $
*
*--------------------------------------------------------------------
*/
bool Password_encryption = true;
+bool default_with_oids = true;
+
int log_min_error_statement = PANIC;
int log_min_messages = NOTICE;
int client_min_messages = NOTICE;
/* QUERY_TUNING */
gettext_noop("Query Tuning"),
/* QUERY_TUNING_METHOD */
- gettext_noop("Query Tuning / Planner Method Enabling"),
+ gettext_noop("Query Tuning / Planner Method Configuration"),
/* QUERY_TUNING_COST */
gettext_noop("Query Tuning / Planner Cost Constants"),
/* QUERY_TUNING_GEQO */
&check_function_bodies,
true, NULL, NULL
},
+ {
+ {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
+ gettext_noop("By default, newly-created tables should have OIDs"),
+ NULL
+ },
+ &default_with_oids,
+ true, NULL, NULL
+ },
/* End-of-list marker */
{
# QUERY TUNING
#---------------------------------------------------------------------------
-# - Planner Method Enabling -
+# - Planner Method Configuration -
#enable_hashagg = true
#enable_hashjoin = true
#add_missing_from = true
#regex_flavor = advanced # advanced, extended, or basic
#sql_inheritance = true
+#default_with_oids = true
# - Other Platforms & Clients -
* by PostgreSQL
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.358 2003/11/29 19:52:05 pgsql Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.359 2003/12/01 22:08:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
appendPQExpBuffer(q, ")");
}
- if (!tbinfo->hasoids)
- appendPQExpBuffer(q, " WITHOUT OIDS");
+ appendPQExpBuffer(q, tbinfo->hasoids ? " WITH OIDS" : " WITHOUT OIDS");
appendPQExpBuffer(q, ";\n");
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.94 2003/11/29 19:52:07 pgsql Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.95 2003/12/01 22:08:01 momjian Exp $
*/
/*----------------------------------------------------------------------
"default_statistics_target",
"default_transaction_isolation",
"default_transaction_read_only",
+ "default_with_oids",
"dynamic_library_path",
"effective_cache_size",
"enable_hashagg",
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
* Written by Peter Eisentraut
.
*
- * $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.42 2003/11/29 22:41:15 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.43 2003/12/01 22:08:02 momjian Exp $
*--------------------------------------------------------------------
*/
#ifndef GUC_H
extern bool SQL_inheritance;
extern bool Australian_timezones;
+extern bool default_with_oids;
+
extern int log_min_error_statement;
extern int log_min_messages;
extern int client_min_messages;
--
-- WITHOUT OID
--
-CREATE TABLE wi (i INT);
+CREATE TABLE wi (i INT) WITH OIDS;
CREATE TABLE wo (i INT) WITHOUT OIDS;
INSERT INTO wi VALUES (1); -- 1
INSERT INTO wo SELECT i FROM wi; -- 1
-- WITHOUT OID
--
-CREATE TABLE wi (i INT);
+CREATE TABLE wi (i INT) WITH OIDS;
CREATE TABLE wo (i INT) WITHOUT OIDS;
INSERT INTO wi VALUES (1); -- 1
INSERT INTO wo SELECT i FROM wi; -- 1