[英]How to create view with the name which can be pass through function as a parameter in postgresql?
我試圖在postgreSQL中使用函數創建一個視圖。 我想要一個視圖名稱,它應該作為參數傳遞給函數。 例如..
- 表
create table test
( rollno int,
name text);
- 創建視圖的功能
create or replace function fun_view(roll int)
returns void as
$Body$
declare
rec record;
begin
for rec in select * from test where rollno=roll loop
create or replace view "---Name of view should be roll---" as
select rollno from test;
end loop;
$Body$
language plpgsql;
您需要PL / PgSQL的動態SQL EXECUTE
命令:
EXECUTE format('create or replace view %I as ...', roll::text);
請參閱:文檔中的PL / PgSQL中的動態SQL 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.