summaryrefslogtreecommitdiff
path: root/src/backend/commands/view.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-03-19 21:37:19 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-03-19 21:38:12 -0400
commit9dbf2b7d75de5af38d087cbe2b1147dd0fd10f0a (patch)
treed58e41d2855f7ac2a5c4c1c4893aaf6f03e1aabc /src/backend/commands/view.c
parent77503a7638a35eedd9cb08d9ca4c54deb203521d (diff)
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
Diffstat (limited to 'src/backend/commands/view.c')
-rw-r--r--src/backend/commands/view.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c
index 99fb7dbb8f4..c887961bc97 100644
--- a/src/backend/commands/view.c
+++ b/src/backend/commands/view.c
@@ -439,9 +439,17 @@ DefineView(ViewStmt *stmt, const char *queryString)
/*
* The grammar should ensure that the result is a single SELECT Query.
+ * However, it doesn't forbid SELECT INTO, so we have to check for that.
*/
- if (!IsA(viewParse, Query) ||
- viewParse->commandType != CMD_SELECT)
+ if (!IsA(viewParse, Query))
+ elog(ERROR, "unexpected parse analysis result");
+ if (viewParse->utilityStmt != NULL &&
+ IsA(viewParse->utilityStmt, CreateTableAsStmt))
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("views must not contain SELECT INTO")));
+ if (viewParse->commandType != CMD_SELECT ||
+ viewParse->utilityStmt != NULL)
elog(ERROR, "unexpected parse analysis result");
/*
@@ -449,10 +457,6 @@ DefineView(ViewStmt *stmt, const char *queryString)
* DefineQueryRewrite(), but that function will complain about a bogus ON
* SELECT rule, and we'd rather the message complain about a view.
*/
- if (viewParse->intoClause != NULL)
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("views must not contain SELECT INTO")));
if (viewParse->hasModifyingCTE)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),