>> 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 ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/users-lounge/docs/faq.html