zoukankan      html  css  js  c++  java
  • PostgreSQL中的onflict

    PostgreSQL 9.5 引入了一项新功能,UPSERT(insert on conflict do),当插入遇到约束错误时,直接返回,或者改为执行UPDATE。

    1、不存在则插入,存在则更新

    insert into test values (1,'test',now()) on conflict (id) do update set info=excluded.info,crt_time=excluded.crt_time; 执行操作:INSERT 0 1 查看结果:select * from test; id | info | crt_time ----+------+---------------------------- 1 | test | 2017-04-24 15:27:25.393948 (1 row) insert into test values (1,'hello digoal',now()) on conflict (id) do update set info=excluded.info,crt_time=excluded.crt_time; INSERT 0 1 查看结果:select * from test; id | info | crt_time ----+--------------+---------------------------- 1 | hello digoal | 2017-04-24 15:27:39.140877 (1 row) 
    

    EXCLUDED 代指要插入的记录

    2、不存在则插入,存在则直接返回(不做任何处理)

    insert into test values (1,'hello digoal',now()) on conflict (id) do nothing; INSERT 0 0 insert into test values (1,'pu',now()) on conflict (id) do nothing; INSERT 0 0 insert into test values (2,'pu',now()) on conflict (id) do nothing; INSERT 0 1 select * from test; id | info | crt_time ----+--------------+---------------------------- 1 | hello digoal | 2017-04-24 15:27:39.140877 2 | pu | 2017-04-24 15:28:20.37392 (2 rows) 
    
  • 相关阅读:
    easyui的页面等待提示层,即mask
    easyui datebox 只选择年月
    java poi Excel导入 整数浮点数转换问题解决
    js去除日期字符串时分秒
    获得元素上的所有属性
    人月神话阅读笔记(二)
    人月神话读后感(一)
    独立冲刺阶段(四)
    独立冲刺阶段(三)
    独立冲刺阶段(二)
  • 原文地址:https://www.cnblogs.com/AganRun/p/11816127.html
Copyright © 2011-2022 走看看