Search Postgresql Archives

Re: Insert data if it is not existing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sorry, i forgot the values.

curr.pgsql.execute('''
INSERT INTO my_table(name, age)
SELECT name, age
WHERE NOT EXISTS(SELECT name FROM my_table WHERE name= name)
''', ('Scott', 23))

Sorry, I don't understand, where should I place the from clause? I just saw a sample code like this in SO, so I gave it a shot


On Thu, May 24, 2018 at 8:04 AM, David G. Johnston <david.g.johnston@xxxxxxxxx> wrote:
On Wednesday, May 23, 2018, tango ward <tangoward15@xxxxxxxxx> 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)


this doesn't give me error but it doesn't insert data either.


I'm doubting your assertion that it doesn't error.   How do you run that query such that age and name are recognized given the main query doesn't have a from clause?

David J.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux