OTA*_*TAR 6 postgresql plpgsql postgresql-9.5
我需要从架构中获取表名,除了一些表
CREATE OR REPLACE FUNCTION func(unnecessary_tables TEXT)
returns void
as $$
begin
EXECUTE 'SELECT table_name FROM information_schema.tables
WHERE
table_schema=''public''
AND
table_name NOT IN( $1 )
' USING unnecessary_tables
--here execute retrieved result, etc ...
end;
$$language plpgsql
Run Code Online (Sandbox Code Playgroud)
然后调用函数
select func('table1'',''table2');
Run Code Online (Sandbox Code Playgroud)
这不是工作和报酬的结果 table1和table2也.
问题是:如何将文本参数传递给存储函数,对于IN运算符?
Clo*_*eto 10
传入文本数组而不是文本:
create or replace function func(unnecessary_tables text[])
returns void as $$
begin
select table_name
from information_schema.tables
where
table_schema = 'public'
and
not(table_name = any($1))
;
end;
$$language plpgsql
Run Code Online (Sandbox Code Playgroud)
称之为:
select func(array['t1','t2']::text[]);
Run Code Online (Sandbox Code Playgroud)
BTW上面的代码可以是普通的SQL而不是PL/pgSQL
| 归档时间: |
|
| 查看次数: |
8483 次 |
| 最近记录: |