8
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;

This gives an error when executed using

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

Error :

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]

What am I doing wrong? I tried various options of passing text with "" and '' and also as passing json

1 Answer 1

10

try:

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

calculationresult(integer, integer, unknown) - PostgreSQL didn't detect type of '{"a":1}', so it ask you to add explicit type casts.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.