Re: insert only if conditions are met?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Henry Ortega <juandelacruz(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: insert only if conditions are met?
Date: 2005-08-31 15:22:21
Message-ID: 2099.1125501741@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Henry Ortega <juandelacruz(at)gmail(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2005-08-31 15:25:34 Re: insert only if conditions are met?
Previous Message Joost Kraaijeveld 2005-08-31 15:14:08 Re: [SQL] How do I copy part of table from db1 to db2