【发布时间】:2014-04-01 03:55:42
【问题描述】:
我们可以在函数的 CASE 条件表达式中使用 SELECT 语句吗?
我尝试了以下功能来完成上述任务。
示例:我有一个函数用于显示包含一些行的表格。
create or replace function test(n integer)
returns table (name text,city text) as
$body$
begin
case n when 1 then
select * from table1
when 2 then
select * from table2
when 3 then
select * from view1
end;
end;
$body$
language plpgsql;
--调用函数
select * from test(1);
/*have to show details of table1*/
select * from test(2);
/*have to show details of table2*/
select * from test(3);
/*have to display details of view1*/
【问题讨论】:
标签: postgresql case plpgsql