pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Andrei Bintintan <klodoma@ar-sd.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: UNIQUE columnt depdening on other column???
Date: Wed, 02 Jun 2004 13:21:53 +0100
Message-ID: <40BDC661.6070305@archonet.com> (raw)
In-Reply-To: <20040602113937.D45E11765F@ar-sd.net>
References: <20040602113937.D45E11765F@ar-sd.net>

Andrei Bintintan wrote:
> Hi, 
>  
> I have a problem.
>  
> Let's say I have the following table:
> CREATE TABLE rekl_element(
> id serial PRIMARY KEY,
> active boolean NOT NULL DEFAULT 'y',
> num int4 NOT NULL,
> text varchar(10)
> );
> 
> Now I want that "num" column is "unique" but only for those columns that
> have active='y'. For the columns that have active='f' I don't care if num is
> unique or not. I'm asking this because num will be doubled some times. 

Non-standard but elegant:
CREATE UNIQUE INDEX my_partially_unique_index ON rekl_element (num) 
WHERE active;


-- 
   Richard Huxton
   Archonet Ltd



view thread (3+ messages)  latest in thread

Message-ID: <40BDC661.6070305@archonet.com>
Permalink:  ../40BDC661.6070305@archonet.com/
Also on:    postgresql.org/message-id/40BDC661.6070305@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, klodoma@ar-sd.net
  Subject: Re: UNIQUE columnt depdening on other column???
  In-Reply-To: <40BDC661.6070305@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox