项目场景:
提示:这里简述项目相关背景:
有时需要delete成功后再update,即影响的行数大于0
问题描述
提示:这里描述项目中遇到的问题:
postgreSQL不支持update xxx delete xxx 的格式
原因分析:
提示:这里填写问题的分析:
因此使用with曲线实现
解决方案:
提示:亲测可用
WITH t1 AS (
delete from test
where id = 5 RETURNING *)
UPDATE test
SET address = 'aaa'
FROM (SELECT count(*) as res FROM t1) t2
where t2.res>0 and id=1