Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id B6031476324 for ; Fri, 15 Nov 2002 10:36:22 -0500 (EST) Received: from anchor-post-39.mail.demon.net (anchor-post-39.mail.demon.net [194.217.242.80]) by postgresql.org (Postfix) with ESMTP id E3EED476395 for ; Fri, 15 Nov 2002 10:30:19 -0500 (EST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-39.mail.demon.net with esmtp (Exim 3.36 #2) id 18CiPy-0002BT-0U for pgsql-docs@postgresql.org; Fri, 15 Nov 2002 15:30:02 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id DA00D17B54 for ; Fri, 15 Nov 2002 15:18:29 +0000 (GMT) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 4CCB316F47 for ; Fri, 15 Nov 2002 15:18:29 +0000 (GMT) Content-Type: text/plain; charset="us-ascii" From: Richard Huxton Organization: Archonet Ltd To: pgsql-docs@postgresql.org Subject: Column and table constraints - anally retentive comments Date: Fri, 15 Nov 2002 15:18:26 +0000 User-Agent: KMail/1.4.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200211151518.26707.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/22 X-Sequence-Number: 1546 Probably just me, but in http://developer.postgresql.org/docs/postgres/ddl-constraints.html#AEN1793 ---begin extract--- price numeric CHECK (price > 0), discounted_price numeric CHECK (discounted_price > 0), CHECK (price > discounted_price) ); The first two constraints should look familiar. The third one uses a new=20 syntax. It is not attached to a particular column, instead it appears as a= =20 separate item in the comma-separated column list. Column definitions and=20 these constraint definitions can be listed in mixed order. We say that the first two constraints are column constraints, whereas the= =20 third one is a table constraint because it is written separately from the= =20 column definitions. Column constraints can also be written as table=20 constraints, while the reverse is not necessarily possible. The above examp= le=20 could also be written as CREATE TABLE products ( product_no integer, name text, price numeric, CHECK (price > 0), discounted_price numeric, CHECK (discounted_price > 0), CHECK (price > discounted_price) ); or even CREATE TABLE products ( product_no integer, name text, price numeric CHECK (price > 0), discounted_price numeric, CHECK (discounted_price > 0 AND price > discounted_price) ); It's a matter of taste.=20 ---end extract--- Not quite taste I'd have thought. Column (value) related constraints should= be=20 written as such, not disconnected from their column. Same principle as=20 declaring variables near to where they are needed. In the example given it would make more sense to have a domain "product_pri= ce"=20 with a constraint on it. Now, I realise we can't do the constraint in 7.3 b= ut=20 later on people will find it easier to maintain if we encourage good=20 behaviour. --=20 Richard Huxton