From 6aa0ef4ad4ee8bca3ad9d38cb57c7f9ce1b83db9 Mon Sep 17 00:00:00 2001
From: Ivan Koptelov <ivan.koptelov@tarantool.org>
Date: Tue, 29 Jan 2019 17:27:19 +0300
Subject: [PATCH] sql: raise an err on CHECK constraint with ON CONFLICT action

Currently all on 'conflict' actions are silently
ignored for 'check' constraints. This patch add
explicit parse-time error.

Closes #3345
---
 src/box/sql/parse.y         |  2 +-
 test/sql-tap/check.test.lua | 37 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 34b405d73e..32ef685b17 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -316,7 +316,7 @@ tcons ::= UNIQUE LP sortlist(X) RP.
                                  {sql_create_index(pParse,0,0,X,0,
                                                    SORT_ORDER_ASC,false,
                                                    SQL_INDEX_TYPE_CONSTRAINT_UNIQUE);}
-tcons ::= CHECK LP expr(E) RP onconf.
+tcons ::= CHECK LP expr(E) RP .
                                  {sql_add_check_constraint(pParse,&E);}
 tcons ::= FOREIGN KEY LP eidlist(FA) RP
           REFERENCES nm(T) eidlist_opt(TA) refargs(R) defer_subclause_opt(D). {
diff --git a/test/sql-tap/check.test.lua b/test/sql-tap/check.test.lua
index 1f369fb02b..4ad2ef576a 100755
--- a/test/sql-tap/check.test.lua
+++ b/test/sql-tap/check.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(58)
+test:plan(61)
 
 --!./tcltestrunner.lua
 -- 2005 November 2
@@ -772,5 +772,40 @@ test:do_execsql_test(
         -- </8.1>
     })
 
+-- gh-3345 : the test checks that ON CONFLICT REPLACE
+-- is not allowed for CHECK constraint.
+test:do_catchsql_test(
+    9.1,
+    [[
+        CREATE TABLE t101 (a INT primary key, b INT, CHECK(b < 10)
+        ON CONFLICT REPLACE)
+    ]], {
+        -- <9.1>
+        1, "keyword \"ON\" is reserved"
+        -- </9.1>
+    })
+
+test:do_catchsql_test(
+    9.2,
+    [[
+        CREATE TABLE t101 (a INT primary key, b INT, CHECK(b < 10)
+        ON CONFLICT ABORT)
+    ]], {
+        -- <9.2>
+        1, "keyword \"ON\" is reserved"
+        -- </9.2>
+    })
+
+test:do_catchsql_test(
+    9.3,
+    [[
+        CREATE TABLE t101 (a INT primary key, b INT, CHECK(b < 10)
+        ON CONFLICT ROLLBACK)
+    ]], {
+        -- <9.3>
+        1, "keyword \"ON\" is reserved"
+        -- </9.3>
+    })
+
 test:finish_test()
 
-- 
GitLab