Use multiple conflict_target in ON CONFLICT clause

前端 未结 9 792
傲寒
傲寒 2020-11-29 02:25

I have two columns in table col1, col2, they both are unique indexed (col1 is unique and so is col2).

I need at insert into this table, u

9条回答
  •  渐次进展
    2020-11-29 02:33

    Kind of hacky but I solved this by concatenating the two values from col1 and col2 into a new column, col3 (kind of like an index of the two) and compared against that. This only works if you need it to match BOTH col1 and col2.

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

    Where col3 = the concatenation of the values from col1 and col2.

提交回复
热议问题