Skip site navigation (1) Skip section navigation (2)

pgsql: Restructure SELECT INTO's parsetree representation intoCreateTa

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Restructure SELECT INTO's parsetree representation intoCreateTa
Date: 2012-03-20 01:38:38
Message-ID: E1S9o22-0000TM-38@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committers
Restructure SELECT INTO's parsetree representation into CreateTableAsStmt.

Making this operation look like a utility statement seems generally a good
idea, and particularly so in light of the desire to provide command
triggers for utility statements.  The original choice of representing it as
SELECT with an IntoClause appendage had metastasized into rather a lot of
places, unfortunately, so that this patch is a great deal more complicated
than one might at first expect.

In particular, keeping EXPLAIN working for SELECT INTO and CREATE TABLE AS
subcommands required restructuring some EXPLAIN-related APIs.  Add-on code
that calls ExplainOnePlan or ExplainOneUtility, or uses
ExplainOneQuery_hook, will need adjustment.

Also, the cases PREPARE ... SELECT INTO and CREATE RULE ... SELECT INTO,
which formerly were accepted though undocumented, are no longer accepted.
The PREPARE case can be replaced with use of CREATE TABLE AS EXECUTE.
The CREATE RULE case doesn't seem to have much real-world use (since the
rule would work only once before failing with "table already exists"),
so we'll not bother with that one.

Both SELECT INTO and CREATE TABLE AS still return a command tag of
"SELECT nnnn".  There was some discussion of returning "CREATE TABLE nnnn",
but for the moment backwards compatibility wins the day.

Andres Freund and Tom Lane

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/9dbf2b7d75de5af38d087cbe2b1147dd0fd10f0a

Modified Files
--------------
src/backend/commands/Makefile              |    2 +-
src/backend/commands/copy.c                |   10 +-
src/backend/commands/createas.c            |  423 +++++++++++++++++++++++++++
src/backend/commands/explain.c             |   73 ++++-
src/backend/commands/portalcmds.c          |    2 +-
src/backend/commands/prepare.c             |   96 +++----
src/backend/commands/view.c                |   16 +-
src/backend/executor/execMain.c            |  434 +---------------------------
src/backend/executor/execUtils.c           |    2 -
src/backend/executor/functions.c           |    4 +-
src/backend/executor/spi.c                 |   34 ++-
src/backend/nodes/copyfuncs.c              |   18 +-
src/backend/nodes/equalfuncs.c             |   15 +-
src/backend/nodes/outfuncs.c               |    2 -
src/backend/nodes/readfuncs.c              |    1 -
src/backend/optimizer/plan/planner.c       |    1 -
src/backend/optimizer/plan/setrefs.c       |   17 +-
src/backend/optimizer/plan/subselect.c     |    1 -
src/backend/optimizer/prep/prepjointree.c  |    6 +-
src/backend/optimizer/util/clauses.c       |    8 +-
src/backend/parser/analyze.c               |  139 +++++++--
src/backend/parser/gram.y                  |   53 ++---
src/backend/parser/parse_clause.c          |    6 -
src/backend/parser/parse_cte.c             |    7 -
src/backend/parser/parse_expr.c            |    6 -
src/backend/rewrite/rewriteDefine.c        |    3 +-
src/backend/tcop/dest.c                    |    4 +-
src/backend/tcop/postgres.c                |    6 +-
src/backend/tcop/pquery.c                  |   39 ++--
src/backend/tcop/utility.c                 |   81 ++++--
src/backend/utils/cache/plancache.c        |   30 +--
src/include/catalog/catversion.h           |    2 +-
src/include/commands/createas.h            |   29 ++
src/include/commands/explain.h             |    7 +-
src/include/commands/prepare.h             |    9 +-
src/include/executor/executor.h            |   11 +-
src/include/nodes/execnodes.h              |    2 -
src/include/nodes/nodes.h                  |    1 +
src/include/nodes/parsenodes.h             |   26 ++-
src/include/nodes/plannodes.h              |    2 -
src/include/parser/analyze.h               |    2 +
src/include/tcop/pquery.h                  |    2 +-
src/include/tcop/utility.h                 |    2 +
src/pl/plpgsql/src/pl_exec.c               |   28 +--
src/test/regress/expected/select_into.out  |   19 ++
src/test/regress/expected/transactions.out |    2 +-
src/test/regress/sql/select_into.sql       |    9 +
47 files changed, 963 insertions(+), 729 deletions(-)

pgsql-committers by date

Next:From: Peter EisentrautDate: 2012-03-20 18:41:06
Subject: pgsql: pg_dump: Remove undocumented "files" output format
Previous:From: Alvaro HerreraDate: 2012-03-19 20:56:42
Subject: pgsql: pg_dump: fix double free of query results

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group