-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Add syntax for to use "IF NOT EXISTS" modifier to "ALTER TABLE add CONSTRAINT" #53007
Comments
@rohany have you looked at this recently in the context of some of your other work? |
I haven't seen this before in PG. I'd imagine that they don't have an ifne clause for constraints because the ifne could make you think you added a constraint of a certain type, which a constraint of a different type satisfied the ifne which is unexpected behavior IMO. |
Slack convo on the topic:
Peter Mattis:
Andrew Werner:
Peter Mattis:
Seems like a strong vote in favor of adding it. |
The lack of |
Previously, it was not possible to execute ALTER TABLE ... ADD CONSTRAINT IF NOT EXISTS ... statements. This commit adds this IF NOT EXISTS modifier to the ADD CONSTRAINT command of the ALTER TABLE statement. When the modifier is present and the defined constraint name already exists in the table, the statement no-ops instead of erroring. Note that this syntax is not supported in PostgreSQL, however PostgreSQL has transactional schema changes and PL/pgSQL which make it possible to achieve the same thing. CockroachDB has none of that yet. Fixes cockroachdb#53007. Release note (sql change): added ALTER TABLE ... ADD CONSTRAINT IF NOT EXISTS.
Previously, it was not possible to execute ALTER TABLE ... ADD CONSTRAINT IF NOT EXISTS ... statements. This commit adds this IF NOT EXISTS modifier to the ADD CONSTRAINT command of the ALTER TABLE statement. When the modifier is present and the defined constraint name already exists in the table, the statement no-ops instead of erroring. Note that this syntax is not supported in PostgreSQL, however PostgreSQL has transactional schema changes and PL/pgSQL which make it possible to achieve the same thing. CockroachDB has none of that yet. This commit also fixes some minor bugs or inconsistencies in the handling of duplicate index names. Fixes cockroachdb#53007. Release note (sql change): added ALTER TABLE ... ADD CONSTRAINT IF NOT EXISTS.
Previously, it was not possible to execute ALTER TABLE ... ADD CONSTRAINT IF NOT EXISTS ... statements. This commit adds this IF NOT EXISTS modifier to the ADD CONSTRAINT command of the ALTER TABLE statement. When the modifier is present and the defined constraint name already exists in the table, the statement no-ops instead of erroring. Note that this syntax is not supported in PostgreSQL, however PostgreSQL has transactional schema changes and PL/pgSQL which make it possible to achieve the same thing. CockroachDB has none of that yet. This commit also fixes some minor bugs or inconsistencies in the handling of duplicate index names. Fixes cockroachdb#53007. Release note (sql change): added ALTER TABLE ... ADD CONSTRAINT IF NOT EXISTS.
71257: sql: Add IF NOT EXISTS modifier to ALTER TABLE ... ADD CONSTRAINT r=postamar a=postamar Previously, it was not possible to execute ALTER TABLE ... ADD CONSTRAINT IF NOT EXISTS ... statements. This commit adds this IF NOT EXISTS modifier to the ADD CONSTRAINT command of the ALTER TABLE statement. When the modifier is present and the defined constraint name already exists in the table, the statement no-ops instead of erroring. Note that this syntax is not supported in PostgreSQL, however PostgreSQL has transactional schema changes and PL/pgSQL which make it possible to achieve the same thing. CockroachDB has none of that yet. Fixes #53007. Release note (sql change): added ALTER TABLE ... ADD CONSTRAINT IF NOT EXISTS. Co-authored-by: Marius Posta <[email protected]>
To simplify pre-check coding, it would be great to have the "IF NOT EXISTS" modifier added. Consider the following example:
Would like to have the following return without throwing an error:
The text was updated successfully, but these errors were encountered: