You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CockroachDB appears to support IF NOT EXISTS in ALTER TABLE ADD CONSTRAINT but this is not documented. See GitHub issue #53007 and the example below:
> create table a (pk integer primary key, p integer, d integer, q integer);
CREATE TABLE
> ALTER TABLE a ADD CONSTRAINT c UNIQUE (p);
ALTER TABLE
> ALTER TABLE a ADD CONSTRAINT c UNIQUE (p);
ERROR: constraint with name "c" already exists
SQLSTATE: 42710
> ALTER TABLE a ADD CONSTRAINT if not exists c UNIQUE (p);
ALTER TABLE
> ALTER TABLE a ADD CONSTRAINT if not exists d UNIQUE (d);
ALTER TABLE
> show create table a;
table_name | create_statement
-------------+----------------------------------------------
a | CREATE TABLE public.a (
| pk INT8 NOT NULL,
| p INT8 NULL,
| d INT8 NULL,
| q INT8 NULL,
| CONSTRAINT a_pkey PRIMARY KEY (pk ASC),
| UNIQUE INDEX c (p ASC),
| UNIQUE INDEX d (d ASC)
| )
(1 row)
Ryan Kuo (taroface) commented:
Lauren Hirata Singh Steven Hand This was indeed covered in the SQL docs reorg - {{IF NOT EXISTS}} is found in the {{ALTER TABLE}} SQL diagram and parameters table for {{ADD CONSTRAINT}}.
Steven Hand (hand-crdb) commented:
Page: https://cockroachlabs.com/docs/v22.2/add-constraint.html
What is the reason for your feedback?
[ ] Missing the information I need
[ ] Too complicated
[ X] Out of date
[ ] Something is broken
[ ] Other
Additional details
CockroachDB appears to support
IF NOT EXISTS
inALTER TABLE ADD CONSTRAINT
but this is not documented. See GitHub issue #53007 and the example below:The above example is from v22.1.13.
Jira Issue: DOC-6648
The text was updated successfully, but these errors were encountered: