Re: array in a reference

From: SZUCS Gábor <surrano(at)mailbox(dot)hu>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: array in a reference
Date: 2003-05-14 16:50:48
Message-ID: 017b01c31a38$f8cf1ec0$0a03a8c0@fejleszt2
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Ries,

----- Original Message -----
From: "Ries van Twisk" <ries(at)jongert(dot)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 ------------------------------

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Luis Sousa 2003-05-14 16:54:30 Re: bad query performance
Previous Message Randall Lucas 2003-05-14 16:46:57 Re: Type coercion on column in a query