Skip to content
Advertisement

Calling stored function in postgres 12 with json type argument by SQL query from pgAdmin results in error

I’m trying to call a stored function in postgres 12 DB which takes 1 parameter of json type and returns result of json type.

The function is like this:

The function must take a json with keys: “id” – for id of request sender, “token” – for it’s secret and “targets” – for ids of target users, as follows:

But when I try calling the function by an SQL query:

I get an error:

I have double checked json, and it seems to be valid. Also a lot of resources present this way of calling functions with json typed parameter. What can be wrong with the way I do it?

Advertisement

Answer

The problem was actually in the function code intself.

First:

This is invalid. The proper way to access json values is simple:

And second:

is missing at the end.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement