Re: Insert data if it is not existing

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, tango ward <tangoward15(at)gmail(dot)com>
Cc: "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-23 19:35:57
Message-ID: 0a76f762-88d8-75a7-de3c-d76094638fdd@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 05/23/2018 10:00 AM, David G. Johnston wrote:
> On Wednesday, May 23, 2018, tango ward <tangoward15(at)gmail(dot)com
> <mailto:tangoward15(at)gmail(dot)com>> wrote:
>
> I just want to ask if it's possible to insert data if it's not
> existing yet.
>
>
> This seems more like a philosophical question than a technical one...
> ​but the answer is yes:
>
> CREATE TABLE test_t (a varchar, b varchar, c integer);
> INSERT INTO test_t
> SELECT '1', '2', 3 WHERE false;​ --where false causes the data to
> effectively "not exist"
>
> As for ON CONFLICT: conflicts can only happen between things that exist.

Well that made my day:)

>
> David J.
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Paolo Crosato 2018-05-23 19:55:55 Re: Error on vacuum: xmin before relfrozenxid
Previous Message Andres Freund 2018-05-23 18:32:38 Re: Error on vacuum: xmin before relfrozenxid