I have a simple function that needs to return an integer from a select statement. This is it:
CREATE OR REPLACE FUNCTION validate(_identityid integer, _postid integer) RETURNS integer
LANGUAGE plpgsql
AS
$$
BEGIN
SELECT postid
FROM post
WHERE
postid = _postid
AND
identityid = _identityid;
END;
$$;
If I run the above function I get the following error:
[42601] ERROR: query has no destination for result data Hint: If you want to discard the results of a SELECT, use PERFORM instead.
Why is there no destination for the result data? Why doesn't it just return the SELECT
statement?