1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Use multiple conflict_target in ON CONFLICT clause

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 3, 2024 às 09:13.

  1. Stack

    Stack Membro Participativo

    I have two separately unique columns in a table: col1, col2. Both have a unique index (col1 is unique and so is col2).

    I need INSERT ... ON CONFLICT ... DO UPDATE syntax, and update other columns in case of a conflict, but I can't use both columns as conflict_target.

    It works:

    INSERT INTO table
    ...
    ON CONFLICT ( col1 )
    DO UPDATE
    SET
    -- update needed columns here


    But how to do this for several columns, something like this:

    ...
    ON CONFLICT ( col1, col2 )
    DO UPDATE
    SET
    ....


    Currently using Postgres 9.5.

    Continue reading...

Compartilhe esta Página