Skip to content

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

Closed
@lachaib

Description

@lachaib

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    op directivespostgresqluse casenot quite a feature and not quite a bug, something we just didn't think of

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions