Re: Insert data if it is not existing

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: tango ward <tangoward15(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Insert data if it is not existing
Date: 2018-05-24 04:11:48
Message-ID: f45d20d9-76c4-5985-9b53-d1549dd60657@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)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(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2018-05-24 04:39:12 Re: Insert data if it is not existing
Previous Message Adrian Klaver 2018-05-24 04:07:26 Re: Insert data if it is not existing