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 7ABF8D7292 for ; Wed, 31 Aug 2005 12:22:38 -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 70676-02 for ; Wed, 31 Aug 2005 15:22:24 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id B4D1CD853E for ; Wed, 31 Aug 2005 12:22:23 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j7VFMLTM002100; Wed, 31 Aug 2005 11:22:21 -0400 (EDT) To: Henry Ortega Cc: pgsql-sql@postgresql.org Subject: Re: insert only if conditions are met? In-reply-to: <2bffcc33050831080942f806e1@mail.gmail.com> References: <2bffcc33050831080942f806e1@mail.gmail.com> Comments: In-reply-to Henry Ortega message dated "Wed, 31 Aug 2005 11:09:54 -0400" Date: Wed, 31 Aug 2005 11:22:21 -0400 Message-ID: <2099.1125501741@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200508/310 X-Sequence-Number: 22538 Henry Ortega writes: > 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 > (condition here.. select sum(ofsomething) from xx where sum(ofsomething)>0 = > ) > Is this possible at all with just plain SQL? Instead of INSERT ... VALUES, use INSERT ... SELECT. regards, tom lane