]> granicus.if.org Git - postgresql/commit
Restructure SELECT INTO's parsetree representation into CreateTableAsStmt.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 20 Mar 2012 01:37:19 +0000 (21:37 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 20 Mar 2012 01:38:12 +0000 (21:38 -0400)
commit9dbf2b7d75de5af38d087cbe2b1147dd0fd10f0a
treed58e41d2855f7ac2a5c4c1c4893aaf6f03e1aabc
parent77503a7638a35eedd9cb08d9ca4c54deb203521d
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
47 files changed:
src/backend/commands/Makefile
src/backend/commands/copy.c
src/backend/commands/createas.c [new file with mode: 0644]
src/backend/commands/explain.c
src/backend/commands/portalcmds.c
src/backend/commands/prepare.c
src/backend/commands/view.c
src/backend/executor/execMain.c
src/backend/executor/execUtils.c
src/backend/executor/functions.c
src/backend/executor/spi.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/setrefs.c
src/backend/optimizer/plan/subselect.c
src/backend/optimizer/prep/prepjointree.c
src/backend/optimizer/util/clauses.c
src/backend/parser/analyze.c
src/backend/parser/gram.y
src/backend/parser/parse_clause.c
src/backend/parser/parse_cte.c
src/backend/parser/parse_expr.c
src/backend/rewrite/rewriteDefine.c
src/backend/tcop/dest.c
src/backend/tcop/postgres.c
src/backend/tcop/pquery.c
src/backend/tcop/utility.c
src/backend/utils/cache/plancache.c
src/include/catalog/catversion.h
src/include/commands/createas.h [new file with mode: 0644]
src/include/commands/explain.h
src/include/commands/prepare.h
src/include/executor/executor.h
src/include/nodes/execnodes.h
src/include/nodes/nodes.h
src/include/nodes/parsenodes.h
src/include/nodes/plannodes.h
src/include/parser/analyze.h
src/include/tcop/pquery.h
src/include/tcop/utility.h
src/pl/plpgsql/src/pl_exec.c
src/test/regress/expected/select_into.out
src/test/regress/expected/transactions.out
src/test/regress/sql/select_into.sql