X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 447169FA192 for ; Fri, 30 Jun 2006 18:55:17 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 19778-05 for ; Fri, 30 Jun 2006 18:55:13 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31813.mail.mud.yahoo.com (web31813.mail.mud.yahoo.com [68.142.207.76]) by postgresql.org (Postfix) with SMTP id AF60C9FA0EC for ; Fri, 30 Jun 2006 18:55:13 -0300 (ADT) Received: (qmail 18289 invoked by uid 60001); 30 Jun 2006 21:55:12 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=sxSa8CpRA1n9+8m9Wz5Hi6tjV8850m7rE90J8y4v1hlZylaZQ322bOFlYkUdPm1hc9k7u6NyTFlqupqviN695ICzDMyaqATbXc4Sr16rt4h8MKkzc3FQXCzjlRNKwcdm3QHfDblA6xYWG2EtSZjpsPugsrYcjECA7dAddGOFFrU= ; Message-ID: <20060630215512.18287.qmail@web31813.mail.mud.yahoo.com> Received: from [24.54.196.198] by web31813.mail.mud.yahoo.com via HTTP; Fri, 30 Jun 2006 14:55:12 PDT Date: Fri, 30 Jun 2006 14:55:12 -0700 (PDT) From: Richard Broersma Jr Subject: Alternative to Select in table check constraint To: General Postgresql List MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/335 X-Sequence-Number: 25571 I am practicing with SQL examples comming from the book: JOE CELKO'S SQL PUZZLES & ANSWERS The following codes doesn't work on PostgreSQL 8.1.4 but according to the book does conform to SQL-92. Is there any other solutions that would result in the same effect? Or is this an example of a contraint that should be avoided at all costs? CREATE TABLE BADGES ( BADGENO SERIAL NOT NULL PRIMARY KEY, EMPNO INTEGER NOT NULL REFERENCES SECEMPLOYEES (EMPNO), ISSUEDATE DATE NOT NULL, STATUS CHAR(1) NOT NULL CHECK ( STATUS IN ('A', 'I')), CHECK ( 1 = ALL ( SELECT COUNT(STATUS) FROM BADGES WHERE STATUS = 'A' GROUP BY EMPNO)) );