pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Raymond O'Donnell <rod@iol.ie>
To: Igor Neyman <ineyman@perceptron.com>
To: tango ward <tangoward15@gmail.com>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Insert data if it is not existing
Date: Fri, 25 May 2018 15:15:13 +0100
Message-ID: <11c14f05-ebe6-cbc7-b31e-f7128876f3d3@iol.ie> (raw)
In-Reply-To: <DM5PR17MB15320A914836368076DCAA35DA690@DM5PR17MB1532.namprd17.prod.outlook.com>
References: <CAA6wQL+TssWQBKuysQWwOK6ggZ5niLiRXhHbZt8hZTC+qsfwXQ@mail.gmail.com>
	<CAKFQuwbovigqheUFx04dr41+H6DbNsRW_meB-w072SFeAPj7vg@mail.gmail.com>
	<0a76f762-88d8-75a7-de3c-d76094638fdd@aklaver.com>
	<CAA6wQLKH+djOs9xVFWB5pG9DN_nD8dQrrdOQtB0=8NdVy93KYA@mail.gmail.com>
	<CAKFQuwa7JFd0ayELKnFD7KmmgNZxTLX_=KVBBqyzq50ngof0Pw@mail.gmail.com>
	<CAA6wQLJ_WNLca0psVifB4Krfz70nJHZVhcnJKZn4EaN3BWy+3g@mail.gmail.com>
	<c9b652fb-13d6-5a40-0ec4-68d12201e1ef@aklaver.com>
	<CAA6wQLJTXC=TRpLocBkjGtnq4sme7TD6uFG1+rtQRabimo_Q5g@mail.gmail.com>
	<6f46b2b5-c69a-fa85-a66b-8ff318a82aa1@aklaver.com>
	<CAA6wQLKgqo9fvyfnsPNL3gmO=1JrN65d6LCcDaH61AreCysptg@mail.gmail.com>
	<DM5PR17MB15320A914836368076DCAA35DA690@DM5PR17MB1532.namprd17.prod.outlook.com>

On 25/05/18 14:35, Igor Neyman wrote:
> 
> '''INSERT INTO my_table(name, age)
> 
> VALUES( %s, %s)
> 
> WHERE NOT EXISTS(SELECT name FROM my_table WHERE name=%s)''', ('Scott', 
> 23, 'Scott'))

I haven't been following this thread, so maybe this has already been 
said, but I think you need a SELECT in there as well:

insert into my_table(name, age)
select 'value 1', 'value 2'
where not exists (
   .....
);

Ray.

-- 
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie




view thread (33+ messages)

Message-ID: <11c14f05-ebe6-cbc7-b31e-f7128876f3d3@iol.ie>
Permalink:  ../11c14f05-ebe6-cbc7-b31e-f7128876f3d3@iol.ie/
Also on:    postgresql.org/message-id/11c14f05-ebe6-cbc7-b31e-f7128876f3d3@iol.ie

 · 

reply

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: rod@iol.ie, ineyman@perceptron.com, tangoward15@gmail.com, adrian.klaver@aklaver.com, david.g.johnston@gmail.com
  Subject: Re: Insert data if it is not existing
  In-Reply-To: <11c14f05-ebe6-cbc7-b31e-f7128876f3d3@iol.ie>
  References: <CAA6wQL+TssWQBKuysQWwOK6ggZ5niLiRXhHbZt8hZTC+qsfwXQ@mail.gmail.com> <CAKFQuwbovigqheUFx04dr41+H6DbNsRW_meB-w072SFeAPj7vg@mail.gmail.com> <0a76f762-88d8-75a7-de3c-d76094638fdd@aklaver.com> <CAA6wQLKH+djOs9xVFWB5pG9DN_nD8dQrrdOQtB0=8NdVy93KYA@mail.gmail.com> <CAKFQuwa7JFd0ayELKnFD7KmmgNZxTLX_=KVBBqyzq50ngof0Pw@mail.gmail.com> <CAA6wQLJ_WNLca0psVifB4Krfz70nJHZVhcnJKZn4EaN3BWy+3g@mail.gmail.com> <c9b652fb-13d6-5a40-0ec4-68d12201e1ef@aklaver.com> <CAA6wQLJTXC=TRpLocBkjGtnq4sme7TD6uFG1+rtQRabimo_Q5g@mail.gmail.com> <6f46b2b5-c69a-fa85-a66b-8ff318a82aa1@aklaver.com> <CAA6wQLKgqo9fvyfnsPNL3gmO=1JrN65d6LCcDaH61AreCysptg@mail.gmail.com> <DM5PR17MB15320A914836368076DCAA35DA690@DM5PR17MB1532.namprd17.prod.outlook.com> <11c14f05-ebe6-cbc7-b31e-f7128876f3d3@iol.ie>

* 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