create function myfn (in tbl (how to define the table input))
as
return set of <some type>
begin
return query AS
select concat(id,name)
from test_tbl
where id in (select id from in_tbl);
end;
现在我想将此表作为输入argtype传递给函数。
select * from myfn(<pass the table - test_tbl>);
如何声明表类型输入参数? 如何用表输入调用此函数?
public async Task FileWriteAsync(string text)
{
string file = @"uid.txt";
using (FileStream sourceStream = new FileStream(file, FileMode.Append, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true))
using (StreamWriter f = new StreamWriter(sourceStream))
{
await f.WriteLineAsync(text);
}
}
public void ExFile(int line)
{
var uid = Regex.Match(txt_ListUID.Lines[line], @"c_user=(.*?);").Groups[1].ToString().Trim();
string text = uid + "|zxzxzx";
_ = FileWriteAsync(text)
}
答案 0 :(得分:0)
您可以使用类型regclass
并建立动态查询
create or replace function myfn (in tbl regclass)
returns TABLE(id INT)
as $$
begin
RETURN QUERY EXECUTE format('select id
from test
where id in (select id from %s)',tbl);
end
$$ LANGUAGE plpgsql;
您使用
调用它select * from myfn('mytablename');