Thread: array in a reference

array in a reference

From
"Ries van Twisk"
Date:
Hey Guys,

I was just wondering if it is possible to use a REFERENCE in a array like
this below:

CREATE TABLE t0 {id    SERIAL,value    TEXT
}

CREATE TABLE t1 {id    SERIAL,t0id    INTEGER[] REFERENCES t0(id)     -- <<<< Is this possible????
}


regards,
Ries van Twisk



Re: array in a reference

From
Stephan Szabo
Date:
On Wed, 7 May 2003, Ries van Twisk wrote:

>
> Hey Guys,
>
> I was just wondering if it is possible to use a REFERENCE in a array like
> this below:
>
> CREATE TABLE t0 {
>     id    SERIAL,
>     value    TEXT
> }
>
> CREATE TABLE t1 {
>     id    SERIAL,
>     t0id    INTEGER[] REFERENCES t0(id)     -- <<<< Is this possible????

Not in this case, it's going to want to compare the entire array to the
id (and will probably fail saying that there's no = operator for _int4 and
int4).



Re: array in a reference

From
SZUCS Gábor
Date:
Ries,

----- Original Message -----
From: "Ries van Twisk" <ries@jongert.nl>
Sent: Wednesday, May 07, 2003 5:07 PM


> CREATE TABLE t0 {
> id SERIAL,
> value TEXT
> }
>
> CREATE TABLE t1 {
> id SERIAL,
> t0id INTEGER[] REFERENCES t0(id)     -- <<<< Is this possible????
> }


I'd use a third table:
 CREATE TABLE t1 (   id SERIAL );
 CREATE TABLE t1_refs_t0 (   t0id integer NOT NULL REFERENCES t0(id),   t1id integer NOT NULL REFERENCES t1(id)
-- Probably you'd like to add some unique constraint (if the orig. array
-- shouldn't contain equal values):   , UNIQUE (t1id, t0id) );

And maybe a trigger (after insert/update on t1) to check that actually there
are rows in the refs table for the new t1.id, but I can't really find out
the correct syntax now :)

G.
--
while (!asleep()) sheep++;

---------------------------- cut here ------------------------------