Skip to content

Add support of IF [NOT] EXISTS for ADD/DROP COLUMN in Postgresql #1626

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

Open
lachaib opened this issue Mar 19, 2025 · 0 comments · May be fixed by #1627
Open

Add support of IF [NOT] EXISTS for ADD/DROP COLUMN in Postgresql #1626

lachaib opened this issue Mar 19, 2025 · 0 comments · May be fixed by #1627
Labels
op directives postgresql use case not quite a feature and not quite a bug, something we just didn't think of

Comments

@lachaib
Copy link
Contributor

lachaib commented Mar 19, 2025

Describe the use case
Add support for IF [NOT] EXISTS for ADDDROP COLUMN operations available on PostgreSQL

Databases / Backends / Drivers targeted
PostgreSQL

Example Use
The goal is to have automatically generated operations rewritable to add if_exists/if_not_exists attributes, then rendered with postgres compiler.

@writer.rewrites(ops.AddColumnOp)
def add_column(autogen_context, _revision, op: ops.AddColumnOp):
    op.if_not_exists = True

would generate following SQL

ALTER TABLE t ADD COLUMN IF NOT EXISTS c INTEGER;

Additional context
Spin-off of #524 for ADD/DROP COLUMN

Have a nice day!

@lachaib lachaib added requires triage New issue that requires categorization use case not quite a feature and not quite a bug, something we just didn't think of labels Mar 19, 2025
lachaib added a commit to lachaib/alembic that referenced this issue Mar 19, 2025
@lachaib lachaib linked a pull request Mar 19, 2025 that will close this issue
3 tasks
@CaselIT CaselIT added postgresql op directives and removed requires triage New issue that requires categorization labels Mar 19, 2025
lachaib added a commit to lachaib/alembic that referenced this issue Mar 19, 2025
lachaib added a commit to lachaib/alembic that referenced this issue Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
op directives postgresql use case not quite a feature and not quite a bug, something we just didn't think of
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants