【问题标题】:postgres json parameter to a functionpostgres json参数到函数
【发布时间】:2015-12-22 12:22:43
【问题描述】:
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}');

错误:

执行 SQL 命令时出错: 错误:函数计算结果(整数,整数,未知)不存在 提示:没有函数匹配给定的名称和参数类型。您可能需要 > 添加显式类型转换。 位置:15 [SQL 状态=42883]

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

【问题讨论】:

    标签: json postgresql


    【解决方案1】:

    尝试:

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

    calculationresult(integer, integer, unknown) - PostgreSQL 没有检测到 '{"a":1}' 的类型,所以它要求你添加显式类型转换。

    【讨论】:

      猜你喜欢
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      相关资源
      最近更新 更多