Re: Can arrays reference primary keys in CREATE TABLE?

From: Luis Sousa <llsousa(at)ualg(dot)pt>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: Filipe Bonjour <fbonjour(at)urbanet(dot)ch>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Can arrays reference primary keys in CREATE TABLE?
Date: 2003-05-14 16:46:17
Message-ID: 3EC272D9.5050203@ualg.pt
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Richard Huxton wrote:

>On Friday 09 May 2003 10:21 pm, Filipe Bonjour wrote:
>
>
>>Hi,
>>
>>I'm a rather new SQL user, and I found interesting that you can
>>use "references" to make sure that a value inserted in a table is a
>>primary key from another table. Something like:
>>
>>
>
>Yep - referential integrity is vital.
>
I used a trigger to get referential integrity.
So, on update or insert, it fires the function that's going to read the
new array and check if really exists on the other table

>
>
>
>>However, I'd like to define a table containing an array, and that
>>all elements of the array be a primary key from another table, so I
>>tried:
>>
>>create table tb (
>> a_ref integer[] references ta(a_id)
>> );
>>
>>But that doesn't work, I think because an array of integers can't
>>be directly compared to an integer.
>>
>>
>
>Don't use arrays, use another table, e.g.
>
>CREATE TABLE tb_items (
> tb_ref integer REFERENCE tb,
> ta_ref integer REFERENCES ta,
> PRIMARY KEY (tb_ref,ta_ref)
>);
>
>
>

--
Luis Sousa
Especialista de Informática
Gabinete de Gestão de Informação, ext: 7837
Campus de Gambelas
Universidade do Algarve, tel: 289800900

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Randall Lucas 2003-05-14 16:46:57 Re: Type coercion on column in a query
Previous Message Larry Rosenman 2003-05-14 16:41:39 Followup from yesterday's PL/pgSQL fun...