在子查询中使用参数
如何在带有“ ”的子查询中使用我的参数? (Postgres v.10)
create or replace function test(p_1 character varying, p_2 character varying)
returns table (id integer, total integer, fruit character varying)
LANGUAGE plpgsql
AS $$
begin
return query
Select * from dblink(
'host=myhost
user=myuser
password=mypw
dbname=mydb',
'select id,total,fruit from fruits
where fruit in (p_1,p_2)') as x(id integer,total integer,fruit varchar);
end;
$$
如果我调用该函数
select * from test('apple','orange')
,我会收到此错误:列“p_1”和“p_2”不存在。.
而不是说 p_1 ,可以使用 $ 符号或其他东西来调用参数。我不知道这是否是真正的方法,但我在任何地方都找不到有关它的任何文档?
How can i use my parameters inside a subquery with ' '? (Postgres v.10)
create or replace function test(p_1 character varying, p_2 character varying)
returns table (id integer, total integer, fruit character varying)
LANGUAGE plpgsql
AS $
begin
return query
Select * from dblink(
'host=myhost
user=myuser
password=mypw
dbname=mydb',
'select id,total,fruit from fruits
where fruit in (p_1,p_2)') as x(id integer,total integer,fruit varchar);
end;
$
If i call the function
select * from test('apple','orange')
I get this ERROR: colum "p_1" and "p_2" does not exist..
Instead of saying p_1 it's possible to call parameters with $ signs or something. I don't know if that's the real approach but i can't find any documentation about it anywhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试这个(未测试):
You can try this (not tested) :