From: Scott Marlowe <smarlowe@g2switchworks.com>
To: Jim C. Nasby <jnasby@pervasive.com>
Cc: Henry Ortega <juandelacruz@gmail.com>
Cc: Ragnar Hafsta? <gnari@simnet.is>
Cc: pgsql-sql@postgresql.org
Subject: Re: insert only if conditions are met?
Date: Wed, 31 Aug 2005 15:50:44 -0500
Message-ID: <1125521444.28179.157.camel@state.g2switchworks.com> (raw)
In-Reply-To: <20050831195406.GG98175@pervasive.com>
References: <2bffcc33050831080942f806e1@mail.gmail.com>
<20050831152534.GA18934@winnie.fuhr.org>
<2bffcc3305083108487fb80cb2@mail.gmail.com>
<2bffcc3305083108497ea6dcc6@mail.gmail.com>
<1125506698.2605.22.camel@localhost.localdomain>
<2bffcc33050831094957be1b4a@mail.gmail.com>
<20050831195406.GG98175@pervasive.com>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: smarlowe@g2switchworks.com, jnasby@pervasive.com, juandelacruz@gmail.com, gnari@simnet.is
Subject: Re: insert only if conditions are met?
In-Reply-To: <1125521444.28179.157.camel@state.g2switchworks.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox