[Sqlalchemy-tickets] Issue #3454: Can't use a CAST in a PostgreSQL ExcludeConstraint (zzzeek/sqlalc
Brought to you by:
zzzeek
|
From: vr2262 <iss...@bi...> - 2015-06-16 14:00:50
|
New issue 3454: Can't use a CAST in a PostgreSQL ExcludeConstraint https://bitbucket.org/zzzeek/sqlalchemy/issue/3454/cant-use-a-cast-in-a-postgresql vr2262: In PostgreSQL I can create a table with an exclusion constraint involving a `CAST` (the `CAST` is necessary because the `UUID` type doesn't have a default operator class for `gist`): ``` #!sql CREATE EXTENSION btree_gist; CREATE TABLE example ( id UUID, some_range INT4RANGE, EXCLUDE USING gist (CAST("id" AS TEXT) WITH =, some_range WITH &&) ); ``` When I try to do the same in SQLAlchemy: ``` #!python from sqlalchemy import * from sqlalchemy.dialects.postgresql import ( UUID, INT4RANGE, ExcludeConstraint, TEXT ) class Example(Base): __tablename__ = 'example' id = Column(UUID) some_range = Column(INT4RANGE) __table_args__ = ( ExcludeConstraint( (cast('id', TEXT), '='), ('some_range', '&&') ), ) ``` I get the `error sqlalchemy.exc.ArgumentError: Can't add unnamed column to column collection`. `('id::TEXT', '=')` doesn't work because SQLAlchemy doesn't recognize `'id::TEXT'` as a column. |