As always, thank you for the complete, exhaustive answer.  This
particular thing is definitely and edge case, and rather non-obvious,
so thank you for walking me through it.

Either of those are clean enough for me!

Is there are more proper / general way to describe the problem, so
google and make this answer easier to find?

Gregg



On Fri, May 29, 2009 at 12:10 PM, Michael Bayer
<mike...@zzzcomputing.com> wrote:
>
> Gregg Lind wrote:
>>
>> I use declarative base for defining classes.
>>
>> I have a constraint that only works in Postgres.  How do I declare
>> that constraint "lowername_check" only if the session is going
>> postgres (and not to sqlite, for example).
>>
>> pg_only_constraint = CheckConstraint("lowername !~
>> '[[:upper:]]'",name='lowername_check'),
>> class Data(Base):
>>     __tablename__ = 'Data'
>>     lowername=Column(Unicode, nullable=False)
>>     __table_args__ = (
>>         pg_only_constraint,  {}
>>         )
>
>
>
> The cleanest way is to use the schema.DDL() construct which can filter
> against various backends, but requires that you spell out the constraint
> explicitly:
>
> DDL("CREATE CONSTRAINT ....", on="postgres").execute_at('after-create',
> Data.__table__)
>
> Alternatively, if you want to stick with the CheckConstraint object you
> can create a function "create_pg_constraints()" which is called at the
> point your app calls "create_engine()", that contains all PG specific
> constructs - the function would be called based on engine.dialect.name ==
> "postgres".
>
> We have a more flexible architecture in 0.6 for this sort of thing and I
> think if we add an AddConstraint() construct there and also move most of
> DDL()'s execute-at and "on" functionality into the base DDLElement class,
> that would enable both constructs to be combined together as in
> AddConstraint(CheckConstraint(...args...),
> on="postgres")).execute_at('after-create', Data.__table__).
>
>
>
>>
>>
>> Thanks!
>>
>> Gregg Lind
>>
>> >
>>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to