Let's say I have a model like:
from sqlalchemy import Column, DateTime, ForeignKey, Text
class Foo(declarative_base):
__tablename__ = "foos"
my_dt = Column(DateTime...)
my_other_value = Column(Integer...)
I'm trying to make a UniqueConstraint
using SqlAlchemy notation that would only allow one my_other_value
per day, which means, I'd like to extract the Date
part of my_dt
and Uniquely constraint it with my_other_value
I know (erm... I'm fairly sure I know, rather) how to do it in PostgreSQL:
CREATE UNIQUE INDEX unique_num_and_date
ON foos(my_other_value, date_trunc('day',my_dt));
but just out of curisity/consitency, I'd like to reflect that using SqlAlchemy.