From: Michael Fuhr <mike@fuhr.org>
To: Henry Ortega <juandelacruz@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: insert only if conditions are met?
Date: Wed, 31 Aug 2005 09:25:34 -0600
Message-ID: <20050831152534.GA18934@winnie.fuhr.org> (raw)
In-Reply-To: <2bffcc33050831080942f806e1@mail.gmail.com>
References: <2bffcc33050831080942f806e1@mail.gmail.com>
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 <condition>;
--
Michael Fuhr
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: mike@fuhr.org, juandelacruz@gmail.com
Subject: Re: insert only if conditions are met?
In-Reply-To: <20050831152534.GA18934@winnie.fuhr.org>
* 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