Re: [SQL] Need help with 'unique parents' constraint

2005-09-14 Thread Daryl Richter
Leif B. Kristensen wrote: On Sunday 11 September 2005 16:04, Greg Sabino Mullane wrote: Not just old-fashioned, it's the biological law! (among homo sapiens anyway). I'd approach this with a trigger, as you can do complex checks and get back nice customized error messages. A sample script foll

Re: [SQL] Need help with `unique parents` constraint

2005-09-12 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > Thank you for an excellent answer. I think I will have to study your > code for a while. But is it such a bad idea to have a separate column > for the primary key here? I see that there are two schools on this, > with diametrically opposed views.

Re: [SQL] Need help with 'unique parents' constraint

2005-09-12 Thread Leif B. Kristensen
On Sunday 11 September 2005 16:04, Greg Sabino Mullane wrote: > Not just old-fashioned, it's the biological law! (among homo sapiens > anyway). I'd approach this with a trigger, as you can do complex > checks and get back nice customized error messages. A sample script > follows. Hard to tell with

Re: [SQL] Need help with 'unique parents' constraint

2005-09-11 Thread John Hasler
Greg Sabino Mullane writes: > Not just old-fashioned, [having only one mother is] the biological law! I see you aren't up on current research. -- John Hasler [EMAIL PROTECTED] Elmwood, WI USA ---(end of broadcast)--- TIP 4: Have you searched our l

Re: [SQL] Need help with 'unique parents' constraint

2005-09-11 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > Now, I want to ensure that each person_id can be assigned only one > father (gender=1) and one mother (gender=2). (Yes, this is old- > fashioned, but I'm working with 18th century people). How do I do it? Not just old-fashioned, it's the biologica

Re: [SQL] Need help with 'unique parents' constraint

2005-09-11 Thread Leif B. Kristensen
On Sunday 11 September 2005 14:24, Leif B. Kristensen wrote: > ALTER TABLE relations ADD CONSTRAINT non_unique_father > CHECK (NOT EXISTS > (SELECT persons.person_id, relations.parent_fk > FROM persons AS P, relations AS R > WHERE R.parent_fk = P.person_id >

[SQL] Need help with 'unique parents' constraint

2005-09-11 Thread Leif B. Kristensen
This message has also been posted to comp.databases. I've got a problem that I can't quite wrap my head around, about adding a constraint to my PostgreSQL genealogy database. If somebody are interested, I've written some thoughts on the general design at . I