Re: conditional insert

From: "J(dot) Hondius" <jhondius(at)rem(dot)nl>
To: Pau Marc Muñoz Torres <paumarc(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: conditional insert
Date: 2011-09-05 11:02:29
Message-ID: 4E64AC45.6030704@rem.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
I agree that there are better ways to do this.<br>
But for me this works. (legacy driven situation)<br>
<br>
INSERT INTO tbinitialisatie (col1, col2)
<br>
&nbsp;SELECT 'x', 'y'
<br>
&nbsp;FROM tbinitialisatie
<br>
&nbsp;WHERE not exists (select * from tbinitialisatie where col1 = 'x' and
col2 = 'y')
<br>
&nbsp;LIMIT 1
<br>
<br>
<br>
Pau Marc Mu&ntilde;oz Torres schreef:
<blockquote
cite="mid:CADFuJLjfHUMEuYTPKgG6GtJMfzJeeq3-bkt162RywRVqc7OYgg(at)mail(dot)gmail(dot)com"
type="cite">Ok , thanks Sim, now i see it<br>
<br>
P<br>
<br>
<div class="gmail_quote">2011/9/5 Sim Zacks <span dir="ltr">&lt;<a
moz-do-not-send="true" href="mailto:sim(at)compulab(dot)co(dot)il">sim(at)compulab(dot)co(dot)il</a>&gt;</span><br>
<blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="direction: ltr;" bgcolor="#ffffff" text="#000000">
<div class="im"> On 09/05/2011 01:37 PM, Pau Marc Mu&ntilde;oz Torres
wrote:
<blockquote type="cite">i don't&nbsp; see it clear, let me put an example<br>
<br>
i got the following table<br>
<br>
molec varchar(30)<br>
seq varchar(100)<br>
<br>
where I insert my values<br>
<br>
&nbsp;lets image that i have a record introduced as ('ubq', 'aadgylpittrs')<br>
<br>
how i can prevent to insert another record where molec='ubq' ?<br>
<br>
thanks<br>
<br>
</blockquote>
</div>
Either put a unique constraint on molec or do<br>
insert into tbl(molec,seq)<br>
select 'ubq', 'aadgylpittrs' where not exists(select molec from tbl
where molec='ubq')<br>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
<b>Pau Marc Mu&ntilde;oz Torres</b><br>
<br>
Laboratori de Biologia Computacional&nbsp;&nbsp; <br>
Institut de&nbsp; Biotecnologia&nbsp;&nbsp; i Biomedicina Vicent Villar&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>
Universitat Autonoma de Barcelona<br>
E-08193 Bellaterra (Barcelona)<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>
tel&egrave;fon:&nbsp; (+34)935 86 89 39<b><br>
Email : <a moz-do-not-send="true"
href="mailto:paumarc(dot)munoz(at)bioinf(dot)uab(dot)cat" target="_blank">paumarc(dot)munoz(at)bioinf(dot)uab(dot)cat</a></b><br>
</blockquote>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 2.5 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Radosław Smogura 2011-09-05 11:05:28 Protocol question - fastpath & parameter status 'S'
Previous Message Pau Marc Muñoz Torres 2011-09-05 10:47:15 Re: conditional insert