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) 
    
  • 相关阅读:
    flash盖住层的解决办法
    编译Chromium
    关于Ubuntu上的版本依赖问题
    GridBagLayout
    使用JList遇到的奇怪问题
    Swing常用整理
    Swing中改变Table的column大小
    SwingUtilities.invokeLater
    git常用命令
    小马过河(bupt 311)
  • 原文地址:https://www.cnblogs.com/AganRun/p/11816127.html
Copyright © 2011-2022 走看看