Re: questions about query design - Mailing list pgsql-general

From Alban Hertroys
Subject Re: questions about query design
Date
Msg-id 460246A9.8010909@magproductions.nl
Whole thread Raw
In response to questions about query design  (Ottavio Campana <ottavio@campana.vi.it>)
Responses Re: questions about query design  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Ottavio Campana wrote:
> Here's an example of what I'm doing: I have a table like
>
> create table (
>   id serial,
>   description text not null,
>   active boolean default true);
>
> 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)?

--
Alban Hertroys
alban@magproductions.nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
   7500 AK Enschede

// Integrate Your World //

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: foreign key constraints with inhertiance, hack suggestions?
Next
From: Devrim GÜNDÜZ
Date:
Subject: Re: Problem on installing postgresql-devel