Skip to content
Snippets Groups Projects
Commit 91d57dce authored by Nikita Pettik's avatar Nikita Pettik Committed by Kirill Yukhin
Browse files

sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY

Table (aka space) can be created without indexes at least from Lua-land
(note that according ANSI SQL table may lack PK). Since there were no
facilities to create primary key constraint on already existing table,
lets extend ADD CONSTRAINT statement with UNIQUE and PRIMARY KEY
clauses. In this case, UNIQUE works exactly in the same way as CREATE
UNIQUE INDEX ... statement does.  In Tarantool primary index is an index
with id == 0, so during execution of ADD CONSTRAINT PRIMARY KEY we check
that there is no any entries in _index space and create that one.
Otherwise, error is raised.

Part of #3097
Follow-up #3914

@TarantoolBot document
Title: ALTER TABLE ADD CONSTRAINT UNIQUE/PK

Currently, tables which lack primary key can take part neither in DDL
nor DQL routines. Attempt to do this leads to error. Such tables
(without PK) may appear as spaces created from Lua NoSQL interface.
To improve NoSQL-SQL interoperability, we are introducing way to add
primary key to already existing table:

ALTER TABLE <table name> ADD CONSTRAINT <constraint name> PRIMARY KEY(<column list>)

And alongside with this another one alias to CREATE UNIQUE INDEX:

ALTER TABLE <table name> ADD CONSTRAINT <constraint name> UNIQUE(<column list>)

Note that Tarantool PK constraint should be explicitly added before
any other unique constraints or secondary indexes. Otherwise, error is
raised: "can not add a secondary key before primary".
parent 1410d729
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment