gpt4 book ai didi

json - 函数的 postgres json 参数

转载 作者:行者123 更新时间:2023-12-04 13:46:20 26 4
gpt4 key购买 nike

CREATE OR REPLACE FUNCTION public.writecalculations(id integer, times integer, j json)
RETURNS text
LANGUAGE plv8
AS
$body$
var overallStart = new Date();
var result = 0;
var insertStmt = "Insert into \"CalculationResult\" Values($1,$2,$3::json)"
result += plv8.execute(insertStmt,[id, times, j]);

var loopEnd = new Date();
return JSON.stringify({"AffectedRows": result, "OverallRuntime": loopEnd-overallStart}) ;
$body$
IMMUTABLE STRICT
COST 100;


COMMIT;

这在使用执行时会出错
WbCall calculationResult(4,4,'{\"a\":1}');

错误 :

An error occurred when executing the SQL command: ERROR: function calculationresult(integer, integer, unknown) does not exist Hint: No function matches the given name and argument types. You might need >to add explicit type casts. Position: 15 [SQL State=42883]



我究竟做错了什么?
我尝试了使用 ""和 '' 传递文本以及传递 json 的各种选项

最佳答案

尝试:

WbCall calculationResult(4,4,'{"a":1}'::json);

计算结果(整数,整数,未知) - PostgreSQL 没有检测到 '{"a":1}' 的类型,因此它要求您添加显式类型转换。

关于json - 函数的 postgres json 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34415864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com