【问题标题】:How to change the schema by arg text in postgres procedure如何在 postgres 过程中通过 arg 文本更改架构
【发布时间】:2019-10-31 02:50:40
【问题描述】:
CREATE OR REPLACE FUNCTION newfunction (Schema1 text, Schema2 text)
RETURNS integer
LANGUAGE plpgsql
SECURITY DEFINER
AS $function$ 
.
.
.
insert into [Schema1].table (name,phone,address,......)
select name,phone,address,..... from [Schema2].table where....;

我想通过 arg 文本更改架构 可以这样做吗?

【问题讨论】:

    标签: postgresql stored-procedures


    【解决方案1】:

    您必须始终使用动态 SQL:

    EXECUTE
       format(
          E'INSERT INTO %I.tab (...)\n'
          'SELECT ... FROM %I.tab WHERE ...',
          schema1,
          schema2
       );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-25
      • 2020-10-03
      • 1970-01-01
      • 2017-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多