-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Milestone
Description
Migrated issue, originally created by v (@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):
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:
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.
Reactions are currently unavailable