[sqlalchemy] Defining a unique constraint on an attribute of a Postgres JSON field

2015-12-30 Thread Andrew Muro
(SQLAlchemy 1.0.11) I'm trying to figure out how to define a unique constraint from within the model when using declarative_base. class User(Base): __tablename__ = 'users' # This obviously doesn't work __table_args__ = ( UniqueConstraint("data->'email'") ) data =

Re: [sqlalchemy] Defining a unique constraint on an attribute of a Postgres JSON field

2015-12-30 Thread Jon Rosebaugh
I think you might want to use the lightweight sqlalchemy.column() (lowercase!) expression; UniqueConstraint(sa.column('data', JSON)['email']) might work. On 12/30/15 5:58 PM, Andrew Muro wrote: (SQLAlchemy 1.0.11) I'm trying to figure out how to define a unique constraint from within the