[英]postgres function is not executing properly
Here I have used like this but not working please provide me the solution在这里我用过这样但不起作用请给我提供解决方案
IF 'select topic1 from tblscmipklimipcmapprovalio2269 t except select miptopic1 from tblmiptopic1master tm' THEN
BEGIN
topic := topic1;
execute 'insert into tblmiptopic1master (miptopic1 , createdby , createdon , updatedby , updatedon , active) values
(topic,22,'',55,'',1)';
END;
```
insert into tblmiptopic1master
(miptopic1, createdby, createdon, updatedby, updatedon, active)
select topic1, 22, '', 55, '', 1
from tblscmipklimipcmapprovalio2269 t
where not exists (
select * from tblmiptopic1master nx
where nx.miptopic1 = t.topic1
);
If you want the topic to be unique, then you should let the database control the data integrity:如果您希望主题唯一,那么您应该让数据库控制数据完整性:
alter table tblmiptopic1master add constraint unq_tblmiptopic1master_miptopic1
unique (miptopic1);
Then you would phrase the insert
as:然后,您可以将
insert
为:
insert into tblmiptopic1master (miptopic1, createdby, createdon, updatedby, updatedon, active)
select topic1, 22, '', 55, '', 1
from tblscmipklimipcmapprovalio2269 t
on conflict (miptopic1) do nothing;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.