From: | tango ward <tangoward15(at)gmail(dot)com> |
---|---|
To: | Adrian Klaver <adrian(dot)klaver(at)aklaver(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-23 23:58:50 |
Message-ID: | CAA6wQLKH+djOs9xVFWB5pG9DN_nD8dQrrdOQtB0=8NdVy93KYA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks masters for responding again.
I've tried running the code:
INSERT INTO my_table(name, age)
SELECT name, age
WHERE NOT EXISTS(SELECT name FROM my_table WHERE name= name)
this doesn't give me error but it doesn't insert data either.
On Thu, May 24, 2018 at 3:35 AM, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:
> 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
>
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2018-05-24 00:04:05 | Re: Insert data if it is not existing |
Previous Message | Joshua D. Drake | 2018-05-23 23:45:29 | Re: Renice on Postgresql process |