X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E15E2476452 for ; Wed, 14 May 2003 11:35:22 -0400 (EDT) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with ESMTP id 65677-07 for ; Wed, 14 May 2003 11:35:20 -0400 (EDT) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by postgresql.org (Postfix) with ESMTP id 4F52B4764B5 for ; Wed, 14 May 2003 11:31:56 -0400 (EDT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-34.mail.demon.net with esmtp (Exim 3.35 #1) id 19FyEV-000J7O-0Y; Wed, 14 May 2003 16:31:55 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id D742F16F38; Wed, 14 May 2003 16:31:51 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 52A1A16F36; Wed, 14 May 2003 16:31:51 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: "Filipe Bonjour" , pgsql-sql@postgresql.org Subject: Re: Can arrays reference primary keys in CREATE TABLE? Date: Wed, 14 May 2003 16:31:48 +0100 User-Agent: KMail/1.4.3 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200305141631.48642.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/278 X-Sequence-Number: 13443 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. > 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) ); --=20 Richard Huxton