Re: insert only if conditions are met? - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: insert only if conditions are met?
Date
Msg-id 20050831152534.GA18934@winnie.fuhr.org
Whole thread Raw
In response to insert only if conditions are met?  (Henry Ortega <juandelacruz@gmail.com>)
List 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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: insert only if conditions are met?
Next
From: Henry Ortega
Date:
Subject: Re: insert only if conditions are met?