I am extremely new to postgresql and do not understand how to set the value of a variable in one function with the value from another function. This is as far as I have got:
Function A
CREATE FUNCTION functiona(_postid integer) RETURNS integer
LANGUAGE SQL
AS
$$
BEGIN
SELECT posttypeid
FROM post
WHERE postid = _postid;
END;
$$;
Function B (which calls Function A to get value)
CREATE OR REPLACE FUNCTION functionb(_postid integer DEFAULT NULL) RETURNS text
LANGUAGE plpgsql
AS
$$
DECLARE _posttypeid int;
BEGIN
IF _postid IS NOT NULL
THEN
_posttypeid := select functiona(_postid); -- want to set value of _posttypeid to the value that comes from functiona
END IF;
END;
$$;
In Function B, how do I set the value of _posttypeid
to be the value that gets returned from Function A?