Skip to content

PrimaryKey and Unique Constraint do not support 'postgresql_include' #10665

@CaselIT

Description

@CaselIT

Discussed in #10664

Originally posted by LeResKP November 20, 2023
When trying to create a PrimaryKeyConstraint postgresql_include is not supported. I checked a bit the code and it seems there is no postgres specific kw allowed for PrimaryKeyConstraint.

This example use alambic, but it's the same when creating a Table().

    op.create_table(
        "user",
        sa.Column("iduser", sa.Integer(), autoincrement=False, nullable=False),
        sa.Column("value", sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint(
            "iduser",
            name="brackethistory_iduser_idproduct_idbracket_date_incl_value_pkey",
            postgresql_include=["value"],
        ),
    )

Here is the error traceback:

  File "/home/aurelien/a9engine/alembic/versions/f0eefd074216_auto.py", line 392, in upgrade
    sa.PrimaryKeyConstraint(
  File "/home/aurelien/venvs/a9engine/lib64/python3.9/site-packages/sqlalchemy/sql/schema.py", line 3839, in __init__
    super(PrimaryKeyConstraint, self).__init__(*columns, **kw)
  File "/home/aurelien/venvs/a9engine/lib64/python3.9/site-packages/sqlalchemy/sql/schema.py", line 3285, in __init__
    Constraint.__init__(self, **kw)
  File "/home/aurelien/venvs/a9engine/lib64/python3.9/site-packages/sqlalchemy/sql/schema.py", line 3129, in __init__
    self._validate_dialect_kwargs(dialect_kw)
  File "/home/aurelien/venvs/a9engine/lib64/python3.9/site-packages/sqlalchemy/sql/base.py", line 428, in _validate_dialect_kwargs
    raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: Argument 'postgresql_include' is not accepted by dialect 'postgresql' on behalf of <class 'sqlalchemy.sql.schema.PrimaryKeyConstraint'>

When creating an index, it works.

    op.create_index(
        "idx_bracketoftest_idbracket", "bracketoftest", ["idbracket"], unique=False, postgresql_include=["idtest"]

Is there a reason this is not working? Or it's a missing feature ?

Thanks in advance for your help

Metadata

Metadata

Assignees

No one assigned

    Labels

    PRs (with tests!) welcomea fix or feature which is appropriate to be implemented by volunteerspostgresqlreflectionreflection of tables, columns, constraints, defaults, sequences, views, everything elseschemathings related to the DDL related objects like Table, Column, CreateIndex, etc.use casenot really a feature or a bug; can be support for new DB features or user use cases not anticipated

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions