From: J. Hondius <jhondius@rem.nl>
To: Pau Marc Muñoz Torres <paumarc@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: conditional insert
Date: Mon, 05 Sep 2011 13:02:29 +0200
Message-ID: <4E64AC45.6030704@rem.nl> (raw)
In-Reply-To: <CADFuJLjfHUMEuYTPKgG6GtJMfzJeeq3-bkt162RywRVqc7OYgg@mail.gmail.com>
References: <CADFuJLjCF6fmxswgS033EFyofmbJFy+J0ToUvwTCDDLYj+nr3Q@mail.gmail.com>
<j4261h$lj8$1@dough.gmane.org>
<CADFuJLi3K0X1A7OwR+9_neWjKCEXtYYyMP_n=x5z=D2+GNCTNw@mail.gmail.com>
<4E64A79E.7030503@compulab.co.il>
<CADFuJLjfHUMEuYTPKgG6GtJMfzJeeq3-bkt162RywRVqc7OYgg@mail.gmail.com>
<!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>
SELECT 'x', 'y'
<br>
FROM tbinitialisatie
<br>
WHERE not exists (select * from tbinitialisatie where col1 = 'x' and
col2 = 'y')
<br>
LIMIT 1
<br>
<br>
<br>
Pau Marc Muñoz Torres schreef:
<blockquote
cite="mid:CADFuJLjfHUMEuYTPKgG6GtJMfzJeeq3-bkt162RywRVqc7OYgg@mail.gmail.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"><<a
moz-do-not-send="true" href="mailto:sim@compulab.co.il">sim@compulab.co.il</a>></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ñoz Torres
wrote:
<blockquote type="cite">i don't 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>
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ñoz Torres</b><br>
<br>
Laboratori de Biologia Computacional <br>
Institut de Biotecnologia i Biomedicina Vicent Villar
<br>
Universitat Autonoma de Barcelona<br>
E-08193 Bellaterra (Barcelona)<br>
<br>
telèfon: (+34)935 86 89 39<b><br>
Email : <a moz-do-not-send="true"
href="mailto:paumarc.munoz@bioinf.uab.cat" target="_blank">paumarc.munoz@bioinf.uab.cat</a></b><br>
</blockquote>
</body>
</html>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: jhondius@rem.nl, paumarc@gmail.com
Subject: Re: conditional insert
In-Reply-To: <4E64AC45.6030704@rem.nl>
References: <CADFuJLjCF6fmxswgS033EFyofmbJFy+J0ToUvwTCDDLYj+nr3Q@mail.gmail.com> <j4261h$lj8$1@dough.gmane.org> <CADFuJLi3K0X1A7OwR+9_neWjKCEXtYYyMP_n=x5z=D2+GNCTNw@mail.gmail.com> <4E64A79E.7030503@compulab.co.il> <CADFuJLjfHUMEuYTPKgG6GtJMfzJeeq3-bkt162RywRVqc7OYgg@mail.gmail.com> <4E64AC45.6030704@rem.nl>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox