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 C7BE5D85AA for ; Wed, 31 Aug 2005 12:49:53 -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 72772-10 for ; Wed, 31 Aug 2005 15:49:46 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.200]) by svr1.postgresql.org (Postfix) with ESMTP id 6566ED84EE for ; Wed, 31 Aug 2005 12:49:45 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id 36so151383wra for ; Wed, 31 Aug 2005 08:49:44 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=uoZisoKdq+Q84rvhTG9CZOzA6p0vKS1ZnxHjLRSxdv61mie5dl3MYRdDefp93C6zZfTSYXuIHrMJcgd3a0PIIVlf6RWAT3KgOtcIK3jmV4Y8GmcRPYU/xDk5mGamK0063tnyZSlgo+9TsvEyu3gwn+fHQWD4ZRb6tKGsIHQe1oE= Received: by 10.54.160.4 with SMTP id i4mr413903wre; Wed, 31 Aug 2005 08:49:44 -0700 (PDT) Received: by 10.54.124.5 with HTTP; Wed, 31 Aug 2005 08:49:44 -0700 (PDT) Message-ID: <2bffcc3305083108497ea6dcc6@mail.gmail.com> Date: Wed, 31 Aug 2005 11:49:44 -0400 From: Henry Ortega To: pgsql-sql@postgresql.org Subject: Re: insert only if conditions are met? In-Reply-To: <2bffcc3305083108487fb80cb2@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_4054_24300173.1125503384609" References: <2bffcc33050831080942f806e1@mail.gmail.com> <20050831152534.GA18934@winnie.fuhr.org> <2bffcc3305083108487fb80cb2@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=-0.056 required=5 tests=[AWL=-0.176, HTML_50_60=0.095, HTML_MESSAGE=0.001, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/312 X-Sequence-Number: 22540 ------=_Part_4054_24300173.1125503384609 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline What I am trying to do is * Insert a record for EMPLOYEE A to TABLE A=20 IF the sum of the hours worked by EMPLOYEE A on TABLE A is not equal to N Is this possible? >=20 >=20 >=20 > On 8/31/05, Michael Fuhr wrote: > >=20 > > 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=20 > > > (condition here.. select sum(ofsomething) from xx where=20 > > sum(ofsomething)>0 ) > >=20 > > See the INSERT documentation; it mentions inserting values from a=20 > > subquery. > >=20 > > INSERT INTO employee > > SELECT 'lastname', 'firstname', 8=20 > > WHERE ; > >=20 > > -- > > Michael Fuhr > >=20 >=20 > ------=_Part_4054_24300173.1125503384609 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 th= ere 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(ofsome= thing)>0 )

See the INSERT documentation; it mentions inserting va= lues from a subquery.

INSERT INTO employee
SELECT 'lastname', 'fi= rstname', 8
WHERE <condition>;

--
Michael Fuhr


------=_Part_4054_24300173.1125503384609--