Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: questions about query design


  • From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
  • To: Alban Hertroys <alban(at)magproductions(dot)nl>
  • Cc: Ottavio Campana <ottavio(at)campana(dot)vi(dot)it>, pgsql-general(at)postgresql(dot)org
  • Subject: Re: questions about query design
  • Date: Thu, 22 Mar 2007 11:11:01 -0400
  • Message-id: <3098(dot)1174576261(at)sss(dot)pgh(dot)pa(dot)us>

Alban Hertroys <alban(at)magproductions(dot)nl> writes:
> Ottavio Campana wrote:
>> What I want to do is a function inserting a new item into the table
>> ensuring that there is only one record in the table having a particular
>> description and at the same time the active field set to true (it might
>> seem stupid, but the application requires it).

> Assuming active can't be NULL, what's wrong with a UNIQUE constraint on
> (description, active)?

I think he does not want descriptions to be unique among non-active
entries.  If so, the right thing is a partial unique index:

CREATE UNIQUE INDEX ... on (description) WHERE active;

			regards, tom lane



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group