Return null from rpc instead of null-filled json #3695
-
I have the function create function "getStory" ("id" uuid) returns "apiStory" language sql
begin atomic
select
s.*
from
"apiStory" s
where
s."storyId" = "getStory"."id";
end; Calling it with rpc with a non-existent id parameter returns {
"storyId":null,
"title":null,
"datePublished":null,
"dateCreated":null,
"dateModified":null,
"authorUserId":null,
"authorName":null
} but I want it to return null. Is it possible currently? If not, I'd like to request this option. Motivation: I want my api to return either a valid object, or null. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You can have your function return create function "getStory" ("id" uuid) returns json language sql
return to_json((
select
s
from
"apiStory" s
where
s."storyId" = "getStory"."id"
)); I think this should do what you want it to. Edit: Slightly adjusted the query. |
Beta Was this translation helpful? Give feedback.
-
Stumbled upon the solution: Change return type to |
Beta Was this translation helpful? Give feedback.
Stumbled upon the solution: Change return type to
record
, instead of the composite type.