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

From Henry Ortega
Subject Re: insert only if conditions are met?
Date
Msg-id 2bffcc3305083108497ea6dcc6@mail.gmail.com
Whole thread Raw
In response to insert only if conditions are met?  (Henry Ortega <juandelacruz@gmail.com>)
Responses Re: insert only if conditions are met?  (Ragnar Hafstað <gnari@simnet.is>)
Re: insert only if conditions are met?  (Chris Travers <chris@metatrontech.com>)
List pgsql-sql
What I am trying to do is
* Insert a record for EMPLOYEE A to TABLE A
IF
the sum of the hours worked by EMPLOYEE A on TABLE A
is not equal to N

Is this possible?







On 8/31/05, Michael Fuhr <mike@fuhr.org> wrote:
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: Michael Fuhr
Date:
Subject: Re: insert only if conditions are met?
Next
From: Ragnar Hafstað
Date:
Subject: Re: insert only if conditions are met?