summaryrefslogtreecommitdiff
path: root/src/backend/commands/createas.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2014-12-13 13:56:09 -0500
committerAndrew Dunstan <andrew@dunslane.net>2014-12-13 13:56:09 -0500
commite39b6f953e8c699eacd676314574ed5869ebacef (patch)
tree420894d9b39ef8e41d302d76b14a4e7e3e54d3f6 /src/backend/commands/createas.c
parente311cd6ded096122a5f2b5cbe91bc3a9f0dda3cb (diff)
Add CINE option for CREATE TABLE AS and CREATE MATERIALIZED VIEW
Fabrízio de Royes Mello reviewed by Rushabh Lathia.
Diffstat (limited to 'src/backend/commands/createas.c')
-rw-r--r--src/backend/commands/createas.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 5e0ac585603..72315c2f3fc 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -28,6 +28,7 @@
#include "access/sysattr.h"
#include "access/xact.h"
#include "access/xlog.h"
+#include "catalog/namespace.h"
#include "catalog/toasting.h"
#include "commands/createas.h"
#include "commands/matview.h"
@@ -86,6 +87,22 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
QueryDesc *queryDesc;
ScanDirection dir;
+ if (stmt->if_not_exists)
+ {
+ Oid nspid;
+
+ nspid = RangeVarGetCreationNamespace(stmt->into->rel);
+
+ if (get_relname_relid(stmt->into->rel->relname, nspid))
+ {
+ ereport(NOTICE,
+ (errcode(ERRCODE_DUPLICATE_TABLE),
+ errmsg("relation \"%s\" already exists, skipping",
+ stmt->into->rel->relname)));
+ return InvalidOid;
+ }
+ }
+
/*
* Create the tuple receiver object and insert info it will need
*/