Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id CF536B5DC1E for ; Mon, 5 Sep 2011 08:20:39 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 57124-05 for ; Mon, 5 Sep 2011 11:20:33 +0000 (UTC) X-Greylist: delayed 00:17:57.640071 by SQLgrey-1.7.6 Received: from zilver.xs4all.nl (nitrogen.xs4all.nl [213.84.19.72]) by mail.postgresql.org (Postfix) with ESMTP id 3CE1AB5DC08 for ; Mon, 5 Sep 2011 08:20:32 -0300 (ADT) Received: from [192.168.85.175] ([192.168.85.175]) by zilver.xs4all.nl (8.11.6/8.11.6) with ESMTP id p85B2O902532; Mon, 5 Sep 2011 13:02:24 +0200 Message-ID: <4E64AC45.6030704@rem.nl> Date: Mon, 05 Sep 2011 13:02:29 +0200 From: "J. Hondius" Reply-To: jhondius@rem.nl Organization: REM Automatisering User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: =?ISO-8859-1?Q?Pau_Marc_Mu=F1oz_Torres?= , pgsql-general@postgresql.org Subject: Re: conditional insert References: <4E64A79E.7030503@compulab.co.il> In-Reply-To: Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.224 tagged_above=-5 required=5 tests=BAYES_05=-0.5, HTML_MESSAGE=0.001, MIME_HTML_ONLY=0.723 X-Spam-Level: X-Archive-Number: 201109/105 X-Sequence-Number: 179463 I agree that there are better ways to do this.
But for me this works. (legacy driven situation)

INSERT INTO tbinitialisatie (col1, col2)
 SELECT 'x', 'y'
 FROM tbinitialisatie
 WHERE not exists (select * from tbinitialisatie where col1 = 'x' and col2 = 'y')
 LIMIT 1


Pau Marc Muñoz Torres schreef:
Ok , thanks Sim, now i see it

P

2011/9/5 Sim Zacks <sim@compulab.co.il>
On 09/05/2011 01:37 PM, Pau Marc Muñoz Torres wrote:
i don't  see it clear, let me put an example

i got the following table

molec varchar(30)
seq varchar(100)

where I insert my values

 lets image that i have a record introduced as ('ubq', 'aadgylpittrs')

how i can prevent to insert another record where molec='ubq' ?

thanks

Either put a unique constraint on molec or do
insert into tbl(molec,seq)
select 'ubq', 'aadgylpittrs' where not exists(select molec from tbl where molec='ubq')



--
Pau Marc Muñoz Torres

Laboratori de Biologia Computacional  
Institut de  Biotecnologia   i Biomedicina Vicent Villar                                   
Universitat Autonoma de Barcelona
E-08193 Bellaterra (Barcelona)
             
telèfon:  (+34)935 86 89 39
Email : paumarc.munoz@bioinf.uab.cat