Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id A5755476151 for ; Mon, 8 Jul 2002 08:36:41 -0400 (EDT) Mailbox-Line: From bruno@wolff.to Mon Jul 8 08:36:41 2002 Received: from wolff.to (wolff.to [66.92.219.49]) by postgresql.org (Postfix) with SMTP id 8B299475F94 for ; Mon, 8 Jul 2002 08:34:47 -0400 (EDT) Received: (qmail 30066 invoked by uid 500); 8 Jul 2002 12:40:13 -0000 Date: Mon, 8 Jul 2002 07:40:13 -0500 From: Bruno Wolff III To: Joachim Trinkwitz Cc: pgsql-sql@postgresql.org Subject: Re: INSERT only under certain conditions (SELECT) Message-ID: <20020708124013.GA30022@wolff.to> Mail-Followup-To: Joachim Trinkwitz , pgsql-sql@postgresql.org References: <874rfb6mqe.fsf@wabe.germanistik.uni-bonn.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <874rfb6mqe.fsf@wabe.germanistik.uni-bonn.de> User-Agent: Mutt/1.3.25i X-Spam-Status: No, hits=-5.3 required=5.0 tests=IN_REP_TO,X_NOT_PRESENT version=2.30 X-Spam-Level: X-Archive-Number: 200207/88 X-Sequence-Number: 8467 On Mon, Jul 08, 2002 at 03:18:33 +0200, Joachim Trinkwitz wrote: > Hi, > > I want to insert a row only under condition that there isn't already > another row with similar values -- something like a INSERT INTO > ... WHERE NOT EXISTS (SELECT ...)? You can do something like the following: insert into tab (col1, col2, col3) select 'val1', 'val2', 'val3' where not exists (select * from tab where col1 = 'val1' and col2 = 'val2' and col3 = 'val3');