postgres - 使用提供临时表的函数创建视图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了postgres - 使用提供临时表的函数创建视图相关的知识,希望对你有一定的参考价值。

我想使用返回临时表的函数创建表视图...

例如,我有一个功能。

create or replace function colpivot(
    out_table varchar
) returns void as $$
    declare
        in_table varchar;
    begin

    create table as select * from employees;
end;

现在我想使用上面的函数给出的临时表(out_table)创建一个视图...

有没有办法做到这一点?

答案

我会修改你的查询如下

create or replace function colpivot(
out_table varchar ) returns void as $$

begin

   select * from employees into out_table ;
   execute 'CREATE OR REPLACE VIEW newView AS ' ||  out_table;

end;
$$ LANGUAGE plpgsql;

以上是关于postgres - 使用提供临时表的函数创建视图的主要内容,如果未能解决你的问题,请参考以下文章