在查询中执行查询(PostgresAdmin III)

问题描述 投票:0回答:1

我有一个很长的清洁程序,有1000次“替换”。我把它保存在一个单独的文件中。所有其他进程在另一个查询中定义。我想从主查询中执行清理文件。这可能吗,怎么做?

示例:主查询文件

create table a as
select * from b;
--a lot of other stuff--

execute cleaning query here!! -- I want to execute the cleaning query within my main query 
-- cleaning query looks as follows (don't want to paste this into main query):
create table a_ as 
select *, replace(replace(replace(...(a1
, 'WORD1', '')
, 'WORD2', '')
, 'WORD3', '')
... from a ;
-- end of cleaning query
--again a lot of stuff --
postgresql pgadmin
1个回答
0
投票

我建议你使用触发器。 PostgreSqlDocumentation: trigger

触发器允许您调用函数(查询);你也可以为每一行声明它,这样你就可以写一个只引用一个通用行的查询,而不是触发器将它应用到表的每一行(你也可以要求满足条件)

© www.soinside.com 2019 - 2024. All rights reserved.