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 model when using declarative_base.

|
classUser(Base):
     __tablename__ ='users'

# This obviously doesn't work
     __table_args__ =(
UniqueConstraint("data->'email'")
)

     data =Column(JSON)

|

Clearly that is the wrong syntax, but is it possible to do via
SQLAlchemy constructs and not directly creating the constraint with the
engine? Our app is already tied to Postgres at this point, but it'd
still be nice to keep everything in the model.

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to