Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback: ADD CONSTRAINT does not document IF NOT EXISTS #16059

Closed
hand-crdb opened this issue Jan 21, 2023 · 2 comments
Closed

Feedback: ADD CONSTRAINT does not document IF NOT EXISTS #16059

hand-crdb opened this issue Jan 21, 2023 · 2 comments
Assignees

Comments

@hand-crdb
Copy link

hand-crdb commented Jan 21, 2023

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 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)

The above example is from v22.1.13.

Jira Issue: DOC-6648

@exalate-issue-sync
Copy link

Lauren Hirata Singh (lnhsingh) commented:
Ryan Kuo - is this update covered by your SQL docs cleanup?

@exalate-issue-sync
Copy link

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}}.

https://www.cockroachlabs.com/docs/stable/alter-table.html#add-constraint

I’ll close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants