Tried it, but it still I am not inserting data into the table.

On Thu, May 24, 2018 at 8:14 AM, tango ward <[email protected]> wrote:

> Oh yeah, my bad. I missed that FROM in SELECT. Sorry, i'll update the code
> now.
>
> On Thu, May 24, 2018 at 8:04 AM, Adrian Klaver <[email protected]>
> wrote:
>
>> On 05/23/2018 04:58 PM, tango ward wrote:
>>
>>> 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)
>>>
>>
>> The first thing I see is that:
>>
>> SELECT name, age
>>
>> is not being selected from anywhere, for example:
>>
>> SELECT name, age FROM some_table.
>>
>> The second thing I see is why not use ON CONFLICT?
>>
>>
>>>
>>> this doesn't give me error but it doesn't insert data either.
>>>
>>> On Thu, May 24, 2018 at 3:35 AM, Adrian Klaver <
>>> [email protected] <mailto:[email protected]>> wrote:
>>>
>>>     On 05/23/2018 10:00 AM, David G. Johnston wrote:
>>>
>>>         On Wednesday, May 23, 2018, tango ward <[email protected]
>>>         <mailto:[email protected]> <mailto:[email protected]
>>>         <mailto:[email protected]>>> 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
>>>     [email protected] <mailto:[email protected]>
>>>
>>>
>>>
>>
>> --
>> Adrian Klaver
>> [email protected]
>>
>
>

Reply via email to