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 7360BD842B for ; Wed, 31 Aug 2005 12:25:50 -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 71072-04 for ; Wed, 31 Aug 2005 15:25:44 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 6EAD0D7292 for ; Wed, 31 Aug 2005 12:25:41 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j7VFPZ1N026249 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 31 Aug 2005 09:25:37 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j7VFPYEM018988; Wed, 31 Aug 2005 09:25:34 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j7VFPY7i018987; Wed, 31 Aug 2005 09:25:34 -0600 (MDT) (envelope-from mfuhr) Date: Wed, 31 Aug 2005 09:25:34 -0600 From: Michael Fuhr To: Henry Ortega Cc: pgsql-sql@postgresql.org Subject: Re: insert only if conditions are met? Message-ID: <20050831152534.GA18934@winnie.fuhr.org> References: <2bffcc33050831080942f806e1@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2bffcc33050831080942f806e1@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 required=5 tests=[AWL=0.005] X-Spam-Level: X-Archive-Number: 200508/311 X-Sequence-Number: 22539 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 > (condition here.. select sum(ofsomething) from xx where sum(ofsomething)>0 ) See the INSERT documentation; it mentions inserting values from a subquery. INSERT INTO employee SELECT 'lastname', 'firstname', 8 WHERE ; -- Michael Fuhr