From 51b673799ed8b1d04b4a1999ec7622988281785a Mon Sep 17 00:00:00 2001
From: Marti Raudsepp <marti@juffo.org>
Date: Fri, 3 Oct 2014 11:21:19 +0300
Subject: [PATCH] Simplify CREATE INDEX IF NOT EXISTS grammar

---
 src/backend/parser/gram.y                  | 12 +-----------
 src/test/regress/expected/create_index.out |  4 ++--
 2 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 47b0a14..d02b730 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -6452,7 +6452,7 @@ IndexStmt:	CREATE opt_unique INDEX opt_concurrently opt_index_name
 					n->initdeferred = false;
 					$$ = (Node *)n;
 				}
-			| CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS opt_index_name
+			| CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS index_name
 			ON qualified_name access_method_clause '(' index_params ')'
 			opt_reloptions OptTableSpace where_clause
 				{
@@ -6461,16 +6461,6 @@ IndexStmt:	CREATE opt_unique INDEX opt_concurrently opt_index_name
 					n->concurrent = $4;
 					n->if_not_exists = true;
 					n->idxname = $8;
-
-					/*
-					 * Throw an exception when IF NOT EXISTS is used without an index name
-					 */
-					if (n->idxname == NULL)
-						ereport(ERROR,
-								(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-								 errmsg("IF NOT EXISTS requires that you name the index."),
-								 parser_errposition(@5)));
-
 					n->relation = $10;
 					n->accessMethod = $11;
 					n->indexParams = $13;
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index ba60fbd..ff866de 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -9,9 +9,9 @@ CREATE INDEX onek_unique1 ON onek USING btree(unique1 int4_ops);
 CREATE INDEX IF NOT EXISTS onek_unique1 ON onek USING btree(unique1 int4_ops);
 NOTICE:  relation "onek_unique1" already exists, skipping
 CREATE INDEX IF NOT EXISTS ON onek USING btree(unique1 int4_ops);
-ERROR:  IF NOT EXISTS requires that you name the index.
+ERROR:  syntax error at or near "ON"
 LINE 1: CREATE INDEX IF NOT EXISTS ON onek USING btree(unique1 int4_...
-                     ^
+                                   ^
 CREATE INDEX onek_unique2 ON onek USING btree(unique2 int4_ops);
 CREATE INDEX onek_hundred ON onek USING btree(hundred int4_ops);
 CREATE INDEX onek_stringu1 ON onek USING btree(stringu1 name_ops);
-- 
2.1.2

