PgSQL的with as语法

时间:2024-04-09 18:44:53

 returning 返回的这一些字段,然后进行汇总为remove_alarms 

然后select一下remove_alarms 出来的数据然后保存到tb_alarm_his 里面

with remove_alarms as(
delete
from
	tb_alarm
where
	id in ('508') 
	returning 
	0,
	now(),
	'admin',
	alarmadvice,
	alarmadvicecn,
	alarmarisestimestamp,
	alarmclass,
	alarmid,
	alarmlevel,
	alarmname,
	alarmnamecn,
	alarmreason,
	alarmreasoncn,
	alarmsequence,
	currentvalue,
	detail,
	ifservicelive,
	locationinfo1,
	locationinfo2,
	nodeip,
	nodename,
	nodeport,
	podname,
	restartreply,
	servicename,
	sourceservice,
	thresholdvalue,
	tenant,
	confirmstatus,
	confirmer,
	alarmconfirmtimestamp)
insert
	into
	tb_alarm_his (alarmtype,
	alarmrecovertimestamp,
	cleaner,
	alarmadvice,
	alarmadvicecn,
	alarmarisestimestamp,
	alarmclass,
	alarmid,
	alarmlevel,
	alarmname,
	alarmnamecn,
	alarmreason,
	alarmreasoncn,
	alarmsequence,
	currentvalue,
	detail,
	ifservicelive,
	locationinfo1,
	locationinfo2,
	nodeip,
	nodename,
	nodeport,
	podname,
	restartreply,
	servicename,
	sourceservice,
	thresholdvalue,
	tenant,
	confirmstatus,
	confirmer,
	alarmconfirmtimestamp)
select
	*
from
	remove_alarms