Re: insert only if conditions are met?

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Henry Ortega <juandelacruz(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: insert only if conditions are met?
Date: 2005-08-31 15:25:34
Message-ID: 20050831152534.GA18934@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Aug 31, 2005 at 11:09:54AM -0400, Henry Ortega wrote:
> Is there a way to insert a record only if a certain
> condition is met?
>
> Something like:
> insert into employee values('lastname','firstname',8) where
> (condition here.. select sum(ofsomething) from xx where sum(ofsomething)>0 )

See the INSERT documentation; it mentions inserting values from a subquery.

INSERT INTO employee
SELECT 'lastname', 'firstname', 8
WHERE <condition>;

--
Michael Fuhr

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Henry Ortega 2005-08-31 15:49:44 Re: insert only if conditions are met?
Previous Message Tom Lane 2005-08-31 15:22:21 Re: insert only if conditions are met?