From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH v2 1/4] sql: rework ALTER TABLE grammar
Date: Thu, 28 Mar 2019 15:07:55 +0300 [thread overview]
Message-ID: <812a298598a9aea10c0a0f887bbf0428835fe67d.1553729426.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1553729426.git.korablev@tarantool.org>
In-Reply-To: <cover.1553729426.git.korablev@tarantool.org>
Since ALTER TABLE ADD CONSTRAINT is going to be used to add various
constraint types (foreign key, unique etc), let's a bit refactor it to
make it more extendable.
Needed for #3097
---
src/box/sql/parse.y | 31 ++++++++++++++++++++++++-------
test/sql-tap/alter2.test.lua | 2 +-
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 4eff61777..0c4603e83 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -1600,18 +1600,35 @@ cmd ::= DROP TRIGGER ifexists(NOERR) fullname(X). {
}
//////////////////////// ALTER TABLE table ... ////////////////////////////////
-cmd ::= ALTER TABLE fullname(X) RENAME TO nm(Z). {
- rename_entity_def_init(&pParse->rename_entity_def, X, &Z);
- sql_alter_table_rename(pParse);
+%include {
+ struct alter_args {
+ struct SrcList *table_name;
+ /** Name of constraint OR new name of table in case of RENAME. */
+ struct Token name;
+ };
+}
+
+%type alter_table_start {struct SrcList *}
+alter_table_start(A) ::= ALTER TABLE fullname(T) . { A = T; }
+
+%type alter_add_constraint {struct alter_args}
+alter_add_constraint(A) ::= alter_table_start(T) ADD CONSTRAINT nm(N). {
+ A.table_name = T;
+ A.name = N;
}
-cmd ::= ALTER TABLE fullname(X) ADD CONSTRAINT nm(Z) FOREIGN KEY
- LP eidlist(FA) RP REFERENCES nm(T) eidlist_opt(TA) matcharg(M)
- refargs(R) defer_subclause_opt(D). {
- create_fk_def_init(&pParse->create_fk_def, X, &Z, FA, &T, TA, M, R, D);
+cmd ::= alter_add_constraint(N) FOREIGN KEY LP eidlist(FA) RP REFERENCES
+ nm(T) eidlist_opt(TA) matcharg(M) refargs(R) defer_subclause_opt(D). {
+ create_fk_def_init(&pParse->create_fk_def, N.table_name, &N.name, FA, &T, TA,
+ M, R, D);
sql_create_foreign_key(pParse);
}
+cmd ::= alter_table_start(A) RENAME TO nm(N). {
+ rename_entity_def_init(&pParse->rename_entity_def, A, &N);
+ sql_alter_table_rename(pParse);
+}
+
cmd ::= ALTER TABLE fullname(X) DROP CONSTRAINT nm(Z). {
drop_fk_def_init(&pParse->drop_fk_def, X, &Z, false);
sql_drop_foreign_key(pParse);
diff --git a/test/sql-tap/alter2.test.lua b/test/sql-tap/alter2.test.lua
index beb6f5d8a..cc1ff5088 100755
--- a/test/sql-tap/alter2.test.lua
+++ b/test/sql-tap/alter2.test.lua
@@ -223,7 +223,7 @@ test:do_catchsql_test(
ALTER TABLE child ADD CONSTRAINT fk FOREIGN KEY REFERENCES child(id);
]], {
-- <alter2-4.1>
- 1, "Syntax error near 'REFERENCES'"
+ 1, "Keyword 'REFERENCES' is reserved. Please use double quotes if 'REFERENCES' is an identifier."
-- </alter2-4.1>
})
--
2.15.1
next prev parent reply other threads:[~2019-03-28 12:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-28 12:07 [tarantool-patches] [PATCH v2 0/4] Introduce ALTER TABLE ADD CONSTRAINT PK/UNIQUE Nikita Pettik
2019-03-28 12:07 ` Nikita Pettik [this message]
2019-03-28 12:07 ` [tarantool-patches] [PATCH v2 2/4] sql: refactor getNewIid() function Nikita Pettik
2019-03-28 15:11 ` [tarantool-patches] " Vladislav Shpilevoy
2019-03-29 18:15 ` n.pettik
2019-04-01 5:17 ` Konstantin Osipov
2019-03-28 12:07 ` [tarantool-patches] [PATCH v2 3/4] sql: fix error message for improperly created index Nikita Pettik
2019-03-28 14:01 ` [tarantool-patches] " Konstantin Osipov
2019-03-28 15:11 ` Vladislav Shpilevoy
2019-03-29 18:16 ` n.pettik
2019-03-28 12:07 ` [tarantool-patches] [PATCH v2 4/4] sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY Nikita Pettik
2019-03-28 15:11 ` [tarantool-patches] " Vladislav Shpilevoy
2019-03-29 18:16 ` n.pettik
2019-04-01 17:58 ` Vladislav Shpilevoy
2019-04-03 7:57 ` [tarantool-patches] Re: [PATCH v2 0/4] Introduce ALTER TABLE ADD CONSTRAINT PK/UNIQUE Kirill Yukhin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=812a298598a9aea10c0a0f887bbf0428835fe67d.1553729426.git.korablev@tarantool.org \
--to=korablev@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [tarantool-patches] [PATCH v2 1/4] sql: rework ALTER TABLE grammar' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox