As usual, works like a charm. The conditional index works as expected in PostgreSQL too, so it's all good.
What methods should I be looking at so I can try and figure some of this stuff out myself. I also want a constraint on a table that for a boolean value, only one can be set to true at one time per each individual foreign key and I have a bunch of triggers I want to write to make totals tables on inserts and updates. In general I like to not have to use raw SQL, but since I will be using PostgreSQL and only PostgreSQL for this project, I don't mind having to do a little bit if I need to. (And I am so glad I don't have to deal with MSSQL this time around.) On Feb 6, 8:43 pm, Jeremy Evans <[email protected]> wrote: > On Feb 6, 1:35 pm, cult hero <[email protected]> wrote: > > > I'm trying to get more and more into the habit of moving a lot of my > > constraints to the database instead of having them in the application. > > However, for all but the most simple constraints (unique, for > > instance) I'm trying to figure out the code for the implementation in > > my migrations. > > > For instance, I want to create some compound unique fields (as in the > > combination of the two fields is unique just like a compound primary > > key). > > A unique index will do that: > > index [:col1, :col2], :unique => true > > > And, is it possible to make the constraints conditional? Such as a > > compound field but the uniqueness is ONLY checked if a third boolean > > field is set to true. As a result if the field is false the uniqueness > > of the two doesn't matter. > > Some databases support partial unique indexes: > > index [:col1, :col2], :unique => true, :where => :col3 > > Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
