From: Bruno Wolff III <bruno@wolff.to>
To: Joachim Trinkwitz <jtr@uni-bonn.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: INSERT only under certain conditions (SELECT)
Date: Mon, 8 Jul 2002 07:40:13 -0500
Message-ID: <20020708124013.GA30022@wolff.to> (raw)
In-Reply-To: <874rfb6mqe.fsf@wabe.germanistik.uni-bonn.de>
References: <874rfb6mqe.fsf@wabe.germanistik.uni-bonn.de>
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');
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, jtr@uni-bonn.de
Subject: Re: INSERT only under certain conditions (SELECT)
In-Reply-To: <20020708124013.GA30022@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox