Re: conditional insert
От | J. Hondius |
---|---|
Тема | Re: conditional insert |
Дата | |
Msg-id | 4E64AC45.6030704@rem.nl обсуждение исходный текст |
Ответ на | Re: conditional insert (Pau Marc Muñoz Torres <paumarc@gmail.com>) |
Ответы |
Re: conditional insert
|
Список | pgsql-general |
I agree that there are better ways to do this.<br /> But for me this works. (legacy driven situation)<br /><br /> INSERTINTO 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 , thanksSim, now i see it<br /><br /> P<br /><br /><div class="gmail_quote">2011/9/5 Sim Zacks <span dir="ltr"><<a href="mailto:sim@compulab.co.il"moz-do-not-send="true">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;"><divbgcolor="#ffffff" style="direction: ltr;" text="#000000"><div class="im"> On 09/05/2011 01:37 PM, Pau Marc MuñozTorres 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 thati 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 /> insertinto 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 href="mailto:paumarc.munoz@bioinf.uab.cat" moz-do-not-send="true" target="_blank">paumarc.munoz@bioinf.uab.cat</a></b><br/></blockquote>
В списке pgsql-general по дате отправления: