当前位置:网站首页>postgresql数据库中根据某个字段判断存在则更新(update)操作,不存在则插入(insert)
postgresql数据库中根据某个字段判断存在则更新(update)操作,不存在则插入(insert)
2022-06-22 05:51:00 【初夏0811】
在实际项目开发过程中,经常会遇到某种业务,根据某个字段判断数据是否存在,若不存在则进行insert操作,若存在则进行根据这个字段update操作:
<insert id="insertProject" parameterType="com.lenovo.mcmp.rm.etl.model.param.resourceConfig.CreateResourceConfigParam">
INSERT INTO project(project_code,project_name,start_time,age)
VALUES(#{
project_code},#{
project_name},'2018-01-10 22:00:00',24)
ON conflict(project_code)
DO UPDATE SET project_name= #{
project_name}, start_time='2018-02-22 12:00:00'
</insert>
也可以根据多个字段判断是否已存在该条数据:
<insert id="insertProject" parameterType="com.lenovo.mcmp.rm.etl.model.param.resourceConfig.CreateResourceConfigParam">
INSERT INTO project(project_code,project_name,start_time,age)
VALUES(#{
project_code},#{
project_name},'2018-01-10 22:00:00',24)
ON conflict(project_code,age)
DO UPDATE SET project_name= #{
project_name}, start_time='2018-02-22 12:00:00'
</insert>
边栏推荐
- Bat common batch script record
- C#中的数组及Foreach遍历
- Improve your game‘s performance
- 402 string (Title: Sword finger offer58 ii. left rotation string, 28. implementation of strstr(), 459 Repeated substrings)
- 单细胞论文记录(part13)--SpaGCN: Integrating gene expression, spatial location and histology to ...
- Market survey and future production and marketing demand analysis report of China's zinc oxide nanoparticle industry 2022-2027
- Single cell thesis records (part9) -- spatial charting of single cell transcriptomes in lectures
- TCP连接细节问题
- Signal output library
- BinaryFormatter 保存和加载游戏数据 For Unity
猜你喜欢

关于MNIST线性模型矩阵顺序问题

Matlab system identification

Adaboost

SQLServer中的子查询

MFC TabCtrl 控件修改标签尺寸

单细胞文献学习(part3)--DSTG: deconvoluting spatial transcriptomics data through graph-based AI

idea插件EasyCode的使用

EMC的解决

Linear regression: least squares, Tellson estimation, RANSAC

Case analysis of terminal data leakage prevention
随机推荐
Using SystemVerilog to describe a state machine
单细胞论文记录(part7)--DL and alignment of spatially resolved single-cell transcriptomes with Tangram
PIR控制器调节器并网逆变器电流谐波抑制策略
Single precision, double precision and precision (Reprint)
Understanding of C pointer
电脑卡顿怎么办?
Frame profiling
Vscode minimalist installation tutorial
EMC的解决
C#中的数组及Foreach遍历
虚职、架空、拖后腿,大厂开源办公室到底什么样?
JTAG interface
文献记录(part106)--GRAPH AUTO-ENCODER VIA NEIGHBORHOOD WASSERSTEIN RECONSTRUCTION
串口(RS - 232)
D3D10 截图功能 保存Texture到本地
Design input of Oracle project management system
时序构成的测试平台
Creating GLSL Shaders at Runtime in Unity3D
Vue des nombres élevés du point de vue de l'espace vectoriel (1) - - Introduction à la série
单球机器人动力学与控制研究