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

From Scott Marlowe
Subject Re: insert only if conditions are met?
Date
Msg-id 1125521444.28179.157.camel@state.g2switchworks.com
Whole thread Raw
In response to Re: insert only if conditions are met?  ("Jim C. Nasby" <jnasby@pervasive.com>)
List pgsql-sql
On Wed, 2005-08-31 at 14:54, Jim C. Nasby wrote:
> SELECT sum(hours) FROM table WHERE emp_name = 'JSMITH' AND work_date =
> '8-15-2005'::date will give you the hours. So...
> 
> INSERT INTO table
>     SELECT blah
>     WHERE (SELECT sum(hours) FROM table WHERE emp_name = 'JSMITH' AND work_date =
> '8-15-2005'::date) != 8
> 
> Should do what you want.

I keep thinking a constraint it a better idea here.  Or is this too
complex to make it one easily.

Either way, I'd make that last part:

<8 instead of !=8, in case this uses floating point instead of int, and
gets 8.0000000001 or what not in it.  Or if someone manages to get it up
to 9 or something.


pgsql-sql by date:

Previous
From: Philip Hallstrom
Date:
Subject: Re: insert only if conditions are met?
Next
From: Daryl Richter
Date:
Subject: Re: insert only if conditions are met?