postgres json parameter to a function

14,113

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.

Share:
14,113
ubreddy
Author by

ubreddy

Updated on June 07, 2022

Comments

  • ubreddy
    ubreddy almost 2 years
    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