Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fATJ8jm99412 for ; Thu, 29 Nov 2001 14:08:46 -0500 (EST) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id fATJ1It04615 for pgsql-sql@postgresql.org; Thu, 29 Nov 2001 14:01:18 -0500 (EST) (envelope-from news) From: reina@nsi.edu (Tony Reina) X-Newsgroups: comp.databases.postgresql.sql Subject: Can I CONSTRAIN a particular value to be UNIQUE? Date: 29 Nov 2001 11:01:11 -0800 Organization: http://groups.google.com/ Lines: 25 Message-ID: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: groups-abuse@google.com To: pgsql-sql@postgresql.org X-Archive-Number: 200111/416 X-Sequence-Number: 5798 I have a table where I'd like to store only one instance where a trial was successful, but all instances where the trial failed. The success or failure is indicated by the field called 'success'. There should be only one unique case for each trial where success = 1, but an undefined number of cases where success = 0. e.g. CREATE TABLE table_1 ( subject text, target int2, trial int4, success int2, data float4 ); CREATE UNIQUE INDEX pktable_1 ON table_1 (subject, target, trial); I'd like to have some way for SQL to give me an error if I attempt to insert more than one instance of a given subject, target, and trial where success = 1, but would allow me to insert as many instances of the same subject, target, and trial where success = 0. Is there a way to do this at table creation time? Thanks. -Tony