Search Postgresql Archives

Re: Insert data if it is not existing

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

 



On 05/23/2018 07:59 PM, tango ward wrote:



On Thu, May 24, 2018 at 10:51 AM, Adrian Klaver

    Try the example I showed previously. If you do not want to use the
    the named parameters e.g %(name)s then use use %s and a tuple like:

    '''
    INSERT INTO my_table(%s, %s)
    WHERE NOT EXISTS(SELECT name FROM my_table WHERE name= %s)
    ''', (Scott', 23, 'Scott'))





        Trying to coordinate with Lead Dev about adding Index On The Fly





-- Adrian Klaver
    adrian.klaver@xxxxxxxxxxx <mailto:adrian.klaver@xxxxxxxxxxx>


Thank you Master, the name=%s solved it.

Please show the complete example that worked for completeness.

FYI, psql is your friend. When I work out queries I try them in psql first and then move up to whatever interface I will be using. This is usually done on a dev server so mistakes don't bring things down. If I have to work on a production instance then I do:
BEGIN;
some_query;
ROLLBACK;


--
Adrian Klaver
adrian.klaver@xxxxxxxxxxx




[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