Re: INSERT only under certain conditions (SELECT) - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: INSERT only under certain conditions (SELECT)
Date
Msg-id 20020708124013.GA30022@wolff.to
Whole thread Raw
In response to INSERT only under certain conditions (SELECT)  (Joachim Trinkwitz <jtr@uni-bonn.de>)
Responses Re: INSERT only under certain conditions (SELECT)
List pgsql-sql
On Mon, Jul 08, 2002 at 03:18:33 +0200, Joachim Trinkwitz <jtr@uni-bonn.de> 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');




pgsql-sql by date:

Previous
From: "Rajesh Kumar Mallah."
Date:
Subject: Re: INSERT only under certain conditions (SELECT)
Next
From: Carmen Wai
Date:
Subject: Problem on PostgreSQL (error code, store procedures)