Received: from gnumed.dhs.org (modem59.malleenet.net.au [203.143.67.123] (may be forged)) by postgresql.org (8.11.3/8.11.4) with SMTP id fAHCDHm04203 for ; Sat, 17 Nov 2001 07:13:19 -0500 (EST) (envelope-from hherb@malleenet.net.au) Received: (qmail 5701 invoked by uid 8); 17 Nov 2001 12:13:12 -0000 Message-ID: <20011117121312.5700.qmail@gnumed.dhs.org> Received: from pc-00071.e-smith.gnumed.dhs.org (192.168.1.71, claiming to be "there") by bifrost.e-smith.gnumed.dhs.org with SMTP id smtpdobXyQF; Sat, 17 Nov 2001 23:13:06 EST Content-Type: text/plain; charset="iso-8859-1" From: Horst Herb To: pgsql-sql@postgresql.org Subject: constraint via selection Date: Sat, 17 Nov 2001 23:18:22 +1100 X-Mailer: KMail [version 1.3.1] MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archive-Number: 200111/250 X-Sequence-Number: 5632 Dear list, I have two simplified tables "country" and "location": create table country ( code char(2) primary key, name varchar(60) ); create table location ( id serial primary key, country char(2) references country(code), [...] ); Location should have a foreign key to country.code, but for performance & ressource reasons it would be much better to have a copy of the country code in location.country rather than a foreign key: create table location ( id serial primary key, country char(2) check ... ); What would the most efficient formulation of the "check" constraint be in this case? Horst