postgresql 判断数据是否存在,存在更新,不存在则插入

INSERT INTO table_name
        (create_time, update_time, name, latest_time)
        VALUES (
        NOW(), 
        NOW(), 
        'name'
        '2023-04-25 19:05:50'
        )
        ON CONFLICT (name) DO UPDATE
        SET update_time=NOW(), 
        target_name='name',
        latest_time='2023-04-25 19:05:50',

重复什么也不做

INSERT INTO table_name
        (create_time, update_time, name, latest_time)
        VALUES (
        NOW(), 
        NOW(), 
        'name'
        '2023-04-25 19:05:50'
        )
        ON CONFLICT (name) DO NOTHING,

你可能感兴趣的:(数据库,postgresql)