Re: Insert data if it is not existing - Mailing list pgsql-general

From David G. Johnston
Subject Re: Insert data if it is not existing
Date
Msg-id CAKFQuwbovigqheUFx04dr41+H6DbNsRW_meB-w072SFeAPj7vg@mail.gmail.com
Whole thread Raw
In response to Insert data if it is not existing  (tango ward <tangoward15@gmail.com>)
Responses Re: Insert data if it is not existing
List pgsql-general
On Wednesday, May 23, 2018, tango ward <tangoward15@gmail.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.

pgsql-general by date:

Previous
From: "a"
Date:
Subject: Re: RE: RE: How do I select composite array element that satisfyspecific conditions.
Next
From: Andres Freund
Date:
Subject: Re: Error on vacuum: xmin before relfrozenxid