From e39b6f953e8c699eacd676314574ed5869ebacef Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Sat, 13 Dec 2014 13:56:09 -0500 Subject: Add CINE option for CREATE TABLE AS and CREATE MATERIALIZED VIEW MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fabrízio de Royes Mello reviewed by Rushabh Lathia. --- src/backend/commands/createas.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/backend/commands/createas.c') diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 5e0ac58560..72315c2f3f 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 */ -- cgit v1.2.1