Alternative to Select in table check constraint

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: General Postgresql List <pgsql-sql(at)postgresql(dot)org>
Subject: Alternative to Select in table check constraint
Date: 2006-06-30 21:55:12
Message-ID: 20060630215512.18287.qmail@web31813.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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))
);

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Broersma Jr 2006-06-30 22:49:36 Re: How To Exclude True Values
Previous Message Markus Schaber 2006-06-30 14:13:11 Re: Views and query planner