pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Henry Ortega <juandelacruz@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: insert only if conditions are met?
Date: Wed, 31 Aug 2005 11:22:21 -0400
Message-ID: <2099.1125501741@sss.pgh.pa.us> (raw)
In-Reply-To: <2bffcc33050831080942f806e1@mail.gmail.com>
References: <2bffcc33050831080942f806e1@mail.gmail.com>

Henry Ortega <juandelacruz@gmail.com> writes:
> 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 =
> )

> Is this possible at all with just plain SQL?

Instead of INSERT ... VALUES, use INSERT ... SELECT.

			regards, tom lane



view thread (14+ messages)  latest in thread

Message-ID: <2099.1125501741@sss.pgh.pa.us>
Permalink:  ../2099.1125501741@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2099.1125501741@sss.pgh.pa.us

 · 

reply

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: tgl@sss.pgh.pa.us, juandelacruz@gmail.com
  Subject: Re: insert only if conditions are met?
  In-Reply-To: <2099.1125501741@sss.pgh.pa.us>

* 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