我想创建一个对表进行操作的函数,例如
create or replace function test(t table)
returns void language plpgsql as
$func$
begin
select * from t limit 10;
end;
$func$
Run Code Online (Sandbox Code Playgroud)
然后,我可以使用任何表名调用该函数,例如
select test(myTable);
Run Code Online (Sandbox Code Playgroud)
我该怎么做这样的事情?
我有一张有不同类型余额的表,我需要根据可用性从不同的列中扣除余额。
这是我尝试使用的查询(示例),但没有用
update table_A
set case
when column_A>table_B.balance then column_A
when column_B>table_B.balance then column_B
when column_C>table_B.balance then column_C
end =value
from table_B
on table_A.Id=table_B.id
Run Code Online (Sandbox Code Playgroud)
谢谢!