Re: Insert data if it is not existing

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: 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 17:00:49
Message-ID: CAKFQuwbovigqheUFx04dr41+H6DbNsRW_meB-w072SFeAPj7vg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wednesday, May 23, 2018, tango ward <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.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andres Freund 2018-05-23 18:32:38 Re: Error on vacuum: xmin before relfrozenxid
Previous Message a 2018-05-23 14:56:10 Re: RE: RE: How do I select composite array element that satisfyspecific conditions.