当前位置:网站首页>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>
边栏推荐
- 【CPU设计实战】数字逻辑电路设计基础(一)
- 单细胞论文记录(part8)--Cell2location maps fine-grained cell types in spatial transcriptomics
- Beifeng helps Nanchang Emergency Management Bureau to build a public-private integrated emergency communication guarantee network
- Unity app提高设备可用性
- Design input of Oracle project management system
- Single cell literature learning (Part2) -- stplus: a reference based method for the exact enhancement of St
- EMC的解决
- MFC TabCtrl 控件修改标签尺寸
- 基于断言的验证
- 时序构成的测试平台
猜你喜欢

Server PHP related web page development environment construction

Compréhension du pointeur C

Use of idea plug-in EASYCODE

RGB, sRGB and XYZ coordinate conversion

雷达导引头伺服系统的建模与仿真

Single cell literature learning (Part2) -- stplus: a reference based method for the exact enhancement of St

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

PID笔记

MFC tabctrl control to modify label size

MFC Tab 控件添加 icon 图标
随机推荐
W800芯片平台进入OpenHarmony主干
Market survey and future production and marketing demand analysis report of China's zinc oxide nanoparticle industry 2022-2027
PIR控制器调节器并网逆变器电流谐波抑制策略
D3D10 screenshot function saves texture to local
System identification of automatic control principle
【技术随记】
U disk as startup disk to reinstall win10 system (no other software required)
电脑卡顿怎么办?
单球机器人动力学与控制研究
TCP connection details
单细胞论文记录(part11)--ClusterMap for multi-scale clustering analysis of spatial gene expression
401 string (344. reverse string, 541. reverse string II, Title: Sword finger offer 05. replace spaces, 151. reverse words in string)
Vscode minimalist installation tutorial
Linear regression: least squares, Tellson estimation, RANSAC
SSM整合所需配置文件及常见配置错误引起的报错
SQLServer中的子查询
Server PHP related web page development environment construction
Academic circle of cattle II (daily question 49 in spring)
matlab 的离散pid控制
【Rust笔记】04-表达式