��  
   I can realize this function in the SYBase,but How can i do it in the PostgreSQL?
  
/****SQL***/
if not exists(select id from test) insert into test(id) values (280);
/*********/ 

_____________________________________________
�����Ʒ�����У��� http://shopping.263.net/category21.htm
��ƷС�ҵ�ӭ������ http://shopping.263.net/category23.htm

Thu, 31 May 2001 13:42:41 +0800 (CST)
"Eric" <e-lz@263.net>
SQL( "if ...exists...),how to do it in the PostgreSQL?
Eric writes:

>    I can realize this function in the SYBase,but How can i do it in the PostgreSQL?
>
> /****SQL***/
> if not exists(select id from test) insert into test(id) values (280);
> /*********/

Write a function in PL/pgSQL.

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Wed, 6 Jun 2001 16:48:34 +0200 (CEST)
Peter Eisentraut <peter_e@gmx.net>
Re: SQL( "if ...exists...),how to do it in the PostgreSQL?
>> if not exists(select id from test) insert into test(id) values (280);

> Write a function in PL/pgSQL.

That particular case could be handled like so:

insert into test(id) select 280 where not exists(select id from test);

The select produces either zero or one row depending on whether its
WHERE is true.  Voila, problem solved.  It's even nearly standard ;-)
although in something like Oracle you'd have to add "from dual", I
think.

			regards, tom lane

Wed, 06 Jun 2001 11:58:49 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: SQL( "if ...exists...),how to do it in the PostgreSQL? 