pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: tango ward <tangoward15@gmail.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: Wed, 23 May 2018 21:11:48 -0700
Message-ID: <f45d20d9-76c4-5985-9b53-d1549dd60657@aklaver.com> (raw)
In-Reply-To: <CAA6wQLLQfN-4e-pSevi77fg9KTL0ijfUdTyLe5B3Co97Gb5o7Q@mail.gmail.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>
	<d6d43665-fdfa-3b88-959f-9bcacc9c1466@aklaver.com>
	<CAA6wQLLQfN-4e-pSevi77fg9KTL0ijfUdTyLe5B3Co97Gb5o7Q@mail.gmail.com>

On 05/23/2018 07:59 PM, tango ward wrote:
> 
> 
> 
> On Thu, May 24, 2018 at 10:51 AM, Adrian Klaver 

>     Try the example I showed previously. If you do not want to use the
>     the named parameters e.g %(name)s then use use %s and a tuple like:
> 
>     '''
>     INSERT INTO my_table(%s, %s)
>     WHERE NOT EXISTS(SELECT name FROM my_table WHERE name= %s)
>     ''', (Scott', 23, 'Scott'))
> 
> 
> 
> 
> 
>         Trying to coordinate with Lead Dev about adding Index On The Fly
> 
> 
> 
> 
> 
>     -- 
>     Adrian Klaver
>     adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
> 
> 
> Thank you Master, the name=%s solved it.

Please show the complete example that worked for completeness.

FYI, psql is your friend. When I work out queries I try them in psql 
first and then move up to whatever interface I will be using. This is 
usually done on a dev server so mistakes don't bring things down. If I 
have to work on a production instance then I do:
BEGIN;
some_query;
ROLLBACK;


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (33+ messages)  latest in thread

Message-ID: <f45d20d9-76c4-5985-9b53-d1549dd60657@aklaver.com>
Permalink:  ../f45d20d9-76c4-5985-9b53-d1549dd60657@aklaver.com/
Also on:    postgresql.org/message-id/f45d20d9-76c4-5985-9b53-d1549dd60657@aklaver.com

 · 

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: adrian.klaver@aklaver.com, tangoward15@gmail.com, david.g.johnston@gmail.com
  Subject: Re: Insert data if it is not existing
  In-Reply-To: <f45d20d9-76c4-5985-9b53-d1549dd60657@aklaver.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> <d6d43665-fdfa-3b88-959f-9bcacc9c1466@aklaver.com> <CAA6wQLLQfN-4e-pSevi77fg9KTL0ijfUdTyLe5B3Co97Gb5o7Q@mail.gmail.com> <f45d20d9-76c4-5985-9b53-d1549dd60657@aklaver.com>

* 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