Re: [HACKERS] Foreign key constraint for array-field?

2008-10-06 Thread Decibel!
On Sep 21, 2008, at 4:18 AM, Simon Riggs wrote: On Sun, 2008-09-21 at 04:38 +0400, Dmitry Koterov wrote: Is it possible to create a foreign key constraint for ALL elements of an array field? CREATE TABLE a(id INTEGER); CREATE TABLE b(id INTEGER, a_ids INTEGER[]); Field b.a_ids contains a

Re: [HACKERS] Foreign key constraint for array-field?

2008-09-21 Thread Simon Riggs
On Sun, 2008-09-21 at 04:38 +0400, Dmitry Koterov wrote: Is it possible to create a foreign key constraint for ALL elements of an array field? CREATE TABLE a(id INTEGER); CREATE TABLE b(id INTEGER, a_ids INTEGER[]); Field b.a_ids contains a list of ID's of a table. I want to ensure

Re: [HACKERS] Foreign key constraint for array-field?

2008-09-21 Thread Dmitry Koterov
Normalization is not a panacea here. Sometimes such normalization creates too much overeat and a lot of additional code (especially if there are a lot of such dependencies). Array support in Postgres is quite handy; in my practive, moving from a_b_map to arrays economizes hundreds of lines of

Re: [HACKERS] Foreign key constraint for array-field?

2008-09-21 Thread Andrew Dunstan
Simon Riggs wrote: No, its not possible. Need a trigger. I think we should support it though. If we extend the relational model with arrays then it would be sensible if we support this aspect as well. Implementation would be fairly straightforward. ri_triggers currently assumes a non-array

Re: [HACKERS] Foreign key constraint for array-field?

2008-09-21 Thread David Fetter
On Sun, Sep 21, 2008 at 10:49:56PM +0400, Dmitry Koterov wrote: Normalization is not a panacea here. Sometimes such normalization creates too much overeat and a lot of additional code (especially if there are a lot of such dependencies). Array support in Postgres is quite handy; in my

Re: [HACKERS] Foreign key constraint for array-field?

2008-09-21 Thread Dmitry Koterov
I strongly suspect you'd benefit a lot more by learning database best practices rather than assuming, as you appear to be doing, that you are dealing with a new field and that you know it best. Neither is true. Of course, you absolutely right. I venerate you! O! :-) -- Sent via

Re: [HACKERS] Foreign key constraint for array-field?

2008-09-21 Thread Simon Riggs
On Sun, 2008-09-21 at 15:07 -0400, Andrew Dunstan wrote: Simon Riggs wrote: No, its not possible. Need a trigger. I think we should support it though. If we extend the relational model with arrays then it would be sensible if we support this aspect as well. Implementation would

[HACKERS] Foreign key constraint for array-field?

2008-09-20 Thread Dmitry Koterov
Hello. Is it possible to create a foreign key constraint for ALL elements of an array field? CREATE TABLE a(id INTEGER); CREATE TABLE b(id INTEGER, a_ids INTEGER[]); Field b.a_ids contains a list of ID's of a table. I want to ensure that each element in b.a_ids exists in a in any time. Is it

Re: [HACKERS] Foreign key constraint for array-field?

2008-09-20 Thread Merlin Moncure
On Sat, Sep 20, 2008 at 8:38 PM, Dmitry Koterov [EMAIL PROTECTED] wrote: Hello. Is it possible to create a foreign key constraint for ALL elements of an array field? CREATE TABLE a(id INTEGER); CREATE TABLE b(id INTEGER, a_ids INTEGER[]); Field b.a_ids contains a list of ID's of a table.

Re: [HACKERS] Foreign key constraint for array-field?

2008-09-20 Thread David Fetter
On Sun, Sep 21, 2008 at 04:38:56AM +0400, Dmitry Koterov wrote: Hello. Is it possible to create a foreign key constraint for ALL elements of an array field? Whether it's possible or not--it probably is--it's a very bad idea. Just normalize :) Cheers, David. -- David Fetter [EMAIL

Re: [HACKERS] Foreign key constraint for array-field?

2008-09-20 Thread Joshua D. Drake
David Fetter wrote: On Sun, Sep 21, 2008 at 04:38:56AM +0400, Dmitry Koterov wrote: Hello. Is it possible to create a foreign key constraint for ALL elements of an array field? Whether it's possible or not--it probably is--it's a very bad idea. Just normalize :) +1 Cheers, David. --