博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
voltdb 记录存在时候更新,不存在时候插入
阅读量:6446 次
发布时间:2019-06-23

本文共 2204 字,大约阅读时间需要 7 分钟。

hot3.png

UPSERTUPSERT — Either inserts new rows or updates existing rows depending on the primary key value.SyntaxUPSERT INTO table-name [( column-name [,...] )] VALUES ( value-expression [,...] )UPSERT INTO table-name [( column-name [,...] )] SELECT select-expression

Description
The UPSERT statement has the same syntax as the INSERT statement and will perform the same function,assuming a record with a matching primary key does not already exist in the database. If such a record does exist, UPSERT updates the existing record with the new column values. Note that the UPSERT statement can only be executed on tables that have a primary key.
UPSERT has the same two forms as the INSERT statement: UPSERT INTO... VALUES and UPSERT
INTO... SELECT. The UPSERT statement also has similar constraints and limitations as the INSERT
statement with regards to joining partitioned tables and overly complex SELECT clauses. (See the description of the INSERT statement for details.)
However, UPSERT INTO... SELECT has an additional limitation: the SELECT statement must produce
deterministically ordered results. That is, the query must not only produce the same rows, they must be in
the same order to ensure the subsequent inserts and updates produce identical results.
Examples
The following examples use two tables, Employee and Manager, both of which define the column emp_id
as a primary key. In the first example, the UPSERT statement either creates a new row with the specified
values or updates an existing row with the primary key 145303.

UPSERT INTO employee (emp_id, lastname, firstname, title, department)VALUES (145303, 'Public', 'Jane', 'Manager', 'HR');

The next example copies records from the Employee table to the Manager table, if the employee's title
is "Manager". Again, new records will be created or existing records updated depending on whether the
employee already has a record in the Manager table. Notice the use of the primary key in an ORDER BY
clause to ensure deterministic results from the SELECT statement.

UPSERT INTO Manager (emp_id, lastname, firstname, title, department)SELECT * from Employee WHERE title='Manager' ORDER BY emp_id;

 

转载于:https://my.oschina.net/u/2308739/blog/749496

你可能感兴趣的文章
git相关知识:如何避免某些文件无需提交
查看>>
Java中Comparable和Comparator区别小结
查看>>
派发机制、动态绑定、静态绑定
查看>>
单节点k8s的一个小例子 webapp+mysql
查看>>
基于tiny4412的Linux内核移植 -- 设备树的展开【转】
查看>>
[转]How to Send Ethereum with Web3.js and Node
查看>>
Java高级个人笔记(RandomStringUtils工具类)
查看>>
FakeUserAgentError('Maximum amount of retries reached') 彻底解决办法
查看>>
[Web 前端] 我不再使用React.setState的3个原因
查看>>
Java队列Queue
查看>>
从软件到片源!PC播放HDTV上手全攻略
查看>>
PowerShell入门(四):如何高效地使用交互式运行环境?
查看>>
linux mount
查看>>
Providesfactories类的应用(转)
查看>>
通过QC远程运行QTP脚本,QTP自动崩溃关闭的解决方法
查看>>
Service生命周期图
查看>>
WinForm:DataGridViewButtonColumn的使用
查看>>
发布一个小工具(HTML、URL编码工具)
查看>>
Step by step teach yourself ruby (一) -- 在ubuntu下搭建语言和开发环境
查看>>
Unity3D游戏开发初探—2.初步了解3D模型基础
查看>>