How Postgresql COPY TO STDIN With CSV do on conflic do update?

前端 未结 3 996
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 14:02

I want to do

 \" on conflict (time) do update set name , description \"

but I have no idea when I use stdin with csv , I don\'t know what n

3条回答
  •  一整个雨季
    2021-01-13 14:06

    In this SO post, there are two answers that -combined together- provide a nice solution for successfully using ON CONFLICT. The example below, uses ON CONFLICT DO NOTHING;:

    CREATE TEMP TABLE tmp_table 
    (LIKE label INCLUDING DEFAULTS)
    ON COMMIT DROP;
    
    COPY tmp_table FROM 'full/file/name/here';
    
    INSERT INTO main_table
    SELECT *
    FROM tmp_table
    ON CONFLICT DO NOTHING;
    

提交回复
热议问题