From: | Scott Marlowe <smarlowe(at)g2switchworks(dot)com> |
---|---|
To: | "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com> |
Cc: | Henry Ortega <juandelacruz(at)gmail(dot)com>, Ragnar Hafsta? <gnari(at)simnet(dot)is>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: insert only if conditions are met? |
Date: | 2005-08-31 20:50:44 |
Message-ID: | 1125521444.28179.157.camel@state.g2switchworks.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Philip Hallstrom | 2005-08-31 21:09:59 | Re: insert only if conditions are met? |
Previous Message | Ragnar Hafstað | 2005-08-31 20:27:58 | Re: insert only if conditions are met? |