X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B84A9D85CC for ; Wed, 31 Aug 2005 13:49:17 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 89882-07 for ; Wed, 31 Aug 2005 16:49:15 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.203]) by svr1.postgresql.org (Postfix) with ESMTP id 48386D84C9 for ; Wed, 31 Aug 2005 13:49:14 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i4so150887wra for ; Wed, 31 Aug 2005 09:49:14 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=qZ8xIxEiFTdepQKLYtfU6/Zw6bRNr3aOWLwQpC1xjUugiWwaAPqjpBgUE2Ziz3KVKXMyNFIw1opZoOmoaSEwYEQwmDEwkZg9zXiXVVveUx6HoBIIqc4WY+tB/NI/31mihe1rxCqaH7qe5Nsjggy775QehGFffrNz212fN7B6s3c= Received: by 10.54.139.19 with SMTP id m19mr811352wrd; Wed, 31 Aug 2005 09:49:14 -0700 (PDT) Received: by 10.54.124.5 with HTTP; Wed, 31 Aug 2005 09:49:14 -0700 (PDT) Message-ID: <2bffcc33050831094957be1b4a@mail.gmail.com> Date: Wed, 31 Aug 2005 12:49:14 -0400 From: Henry Ortega To: =?ISO-8859-1?Q?Ragnar_Hafsta=F0?= Subject: Re: insert only if conditions are met? Cc: pgsql-sql@postgresql.org In-Reply-To: <1125506698.2605.22.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_4643_19900193.1125506954839" References: <2bffcc33050831080942f806e1@mail.gmail.com> <20050831152534.GA18934@winnie.fuhr.org> <2bffcc3305083108487fb80cb2@mail.gmail.com> <2bffcc3305083108497ea6dcc6@mail.gmail.com> <1125506698.2605.22.camel@localhost.localdomain> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=-0.038 required=5 tests=[AWL=-0.158, HTML_50_60=0.095, HTML_MESSAGE=0.001, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/314 X-Sequence-Number: 22542 ------=_Part_4643_19900193.1125506954839 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Ok. Here's TABLE A emp date hours type JSMITH 08-15-2005 5 WORK JSMITH 08-15-2005 3 WORK JSMITH 08-25-2005 6 WORK I want to insert the ff: 1.) JSMITH 08-15-2005 8 VAC 2.) DOE 08-16-2005 8 VAC #1 should fail because there is already 8 hours entered as being Worked on 08-15-2005 (same date). Any suggestions? On 8/31/05, Ragnar Hafsta=F0 wrote: >=20 > On Wed, 2005-08-31 at 11:49 -0400, Henry Ortega wrote: > > 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? >=20 > Sure, given a suitable schema >=20 > It is not clear to me, if the hours worked are > to be found in the same table you want to insert > into, or not. >=20 > gnari >=20 >=20 >=20 > ------=_Part_4643_19900193.1125506954839 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Ok. Here's TABLE A

emp            date            = ; hours       type
JSMITH       08-15-2005   5             WORK
JSMITH       08-15-2005   3             WORK
JSMITH       08-25-2005   6             WORK

I want to insert the ff:
1.) JSMITH    08-15-2005    8  &nbs= p; VAC
2.) DOE        08-16-2005  &nb= sp; 8    VAC

#1 should fail because there is already 8 hours entered as being
Worked on 08-15-2005 (same date).

Any suggestions?



On 8/31/05, Ragnar Hafsta=F0 <gnari@s= imnet.is> wrote:
On Wed, 2005-08-31 at 11:49 -0400, Henry Ortega wrote:
> What I am tr= ying to do is
> * Insert a record for EMPLOYEE A to TABLE A
> I= F
> the sum of the hours worked by EMPLOYEE A on TABLE A
> is n= ot equal to N
>
> Is this possible?

Sure, given a suitable schema
=
It is not clear to me, if the hours worked are
to be found in the sa= me table you want to insert
into, or not.

gnari




------=_Part_4643_19900193.1125506954839--