任何人都可以帮助以下链接修改光标
Posted
技术标签:
【中文标题】任何人都可以帮助以下链接修改光标【英文标题】:Can anybody help be for below link modified cursor 【发布时间】:2016-10-20 06:26:28 【问题描述】:我修改了我的函数来执行一些 json 对象
cursor loop in PostgreSQL
我有查询返回以下结果
SELECT asn."Id",asn."UserId",asn."ActivityId",pd."DataSourceId",ad."Dump"
FROM "Development"."ActivitySession" as asn inner join "Development"."PersonDataSource" as pd on pd."UserId" = asn."UserId" inner join "Development"."ActivitySessionDump" as ad
on asn."Id"=ad."ActivitySessionId" where asn."CreatedAt" between now() - interval '5 days' and now() and asn."ActivityId"=1 and pd."DataSourceId"=1
Id UserId ActId DId Dump
42594890910270849 42031336811660529 1 1 "activities-steps":["dateTime":"2016-10-17","value":"4023"]
42595097786975653 42031336811660529 1 1 "activities-steps":["dateTime":"2016-10-17","value":"4023"]
42597154682570183 42031336811660529 1 1 "activities-steps":["dateTime":"2016-10-17","value":"5388"]
42602824351352325 42031336811660529 1 1 "activities-steps":["dateTime":"2016-10-18","value":"0"]
42605659177354793 42031336811660529 1 1 "activities-steps":["dateTime":"2016-10-18","value":"0"]
42611328851117671 42031336811660529 1 1 "activities-steps":["dateTime":"2016-10-18","value":"0"]
我在下面写了一个函数
CREATE OR REPLACE FUNCTION ThirdPartyDataParse()
RETURNS text AS $$
DECLARE
sessionid NO SCROLL CURSOR FOR SELECT asn."Id",asn."UserId",asn."ActivityId",pd."DataSourceId",ad."Dump"
FROM "Development"."ActivitySession" as asn inner join "Development"."PersonDataSource" as pd on pd."UserId" = asn."UserId" inner join "Development"."ActivitySessionDump" as ad
on asn."Id"=ad."ActivitySessionId" where asn."CreatedAt" between now() - interval '5 days' and now() and asn."ActivityId"=1 and pd."DataSourceId"=1 for read only;
titles TEXT DEFAULT '';
rec record;
jsonrec record;
BEGIN
OPEN sessionid;
loop
FETCH sessionid INTO rec;
--raise notice '%d',rec."UserId";
if not found then
exit ;
end if;
--titles := titles || ',' || rec."Dump";
EXECUTE 'SELECT rec."Dump"::json#>''activities-steps,0''->>''value''' INTO jsonrec;
titles := titles || ',' || jsonrec."steps";
end loop;
return titles;
END;
$$ LANGUAGE plpgsql;
但我无法执行
EXECUTE 'SELECT rec."dump"::json#>''activities-steps,0''->>''value''' INTO jsonrec;
rec."dump" 这里等于 "activities-steps":["dateTime":"2016-10-17","value":"4023"],所以我的查询就像
SELECT '"activities-steps":["dateTime":"2016-10-17","value":"4023"]'::json#>'activities-steps,0'->>'value' as steps;
但我无法执行这个内部函数错误是:
Error in query: ERROR: missing FROM-clause entry for table "rec"
LINE 1: SELECT rec."Dump"::json#>'activities-steps,0'->>'value'
QUERY: SELECT rec."Dump"::json#>'activities-steps,0'->>'value'
CONTEXT: PL/pgSQL function thirdpartydataparse() line 19 at EXECUTE statement
【问题讨论】:
【参考方案1】:您不能在命令字符串中包含对 PL/pgSQL 变量的引用。 SQL 解析器不知道这些变量,因此它假定您正在请求表 rec
的属性 "Dump"
,然后如果该表没有 FROM
子句,则会抱怨。
你需要像这样使用EXECUTE ... USING
:
EXECUTE 'SELECT $1::json#>''activities-steps,0''->>''value'''
INTO jsonrec USING rec."Dump";
【讨论】:
我想使用 EXECUTE 'INSERT INTO "Development"."ActivitySessionParameter" ("ActivitySessionId", "GameParameterId", "Value") VALUES (rec."Id",rec." ActivityId", jsonrec."steps")';但错误是查询中的错误:错误:缺少表“rec”的 FROM 子句条目以上是关于任何人都可以帮助以下链接修改光标的主要内容,如果未能解决你的问题,请参考以下文章
改进 LinkLabel - 使用系统手形光标和更改链接颜色
我需要构建一个休息客户端,以便在 Java 中以最佳性能进行 10k 次休息 api 调用/执行应用程序。任何有用的链接都会有所帮助