如何解决使用ANY$ 1
我有一个表格(lrecords
)
------------------------------------------
| UserId | Timestamp | Key | Value |
------------------------------------------
99 | 1598603308 | Spo2 | 99
99 | 1598603318 | Spo2 | 98
99 | 1598603328 | Spo2 | 96
99 | 1598603338 | Spo2 | 97
...
...
99 | 1598603307 | Breath | 99
99 | 1598603311 | Breath | 98
99 | 1598603315 | Breath | 96
99 | 1598603319 | Breath | 97
...
这是我要编写的功能
CREATE OR REPLACE FUNCTION public.test(
"UserIds" uuid[])
RETURNS record
LANGUAGE 'plpgsql'
COST 100
VOLATILE
AS $BODY$
BEGIN
EXECUTE $$
select json_agg(rows) as "LatestRecords" from (
select "RowId"[1] as "UserId","RowId"[2] as "Timestamp","HeartRate","BreathRate","Sdnn","Temperature","Spo2","PlusStage"
from crosstab('select ''{"UserId","Timestamp"}''::text[],"Key","Value" from lrecords where "UserId" = ANY($1)')
AS ct("RowId" text[],"HeartRate" real,"BreathRate" real,"Sdnn" real,"Temperature" real,"Spo2" real,"PlusStage" real)) rows
$$ using "UserIds";
END;
$BODY$;
ALTER FUNCTION public.test(uuid[])
OWNER TO postgres;
我得到的错误是
ERROR: there is no parameter $1
LINE 1: ...ext[],"Value" from lrecords where "UserId" = ANY($1)
uuid数组确实可以在其他函数中工作,但是当其在crosstab
中时不起作用。我尝试将crosstab
中的语句更改为
'select ''{"UserId","Value" from lrecords where "UserId" = ANY('||$1||')
但没有帮助。
我不确定这里缺少什么。任何帮助表示赞赏:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。