Reputation: 3
I am trying to understand how to set an output value in a user created functions in postgres. So I made this simple function:
CREATE OR REPLACE FUNCTION test()
RETURNS BOOLEAN AS $return_value$
DECLARE return_value BOOLEAN;
BEGIN
SET return_value = TRUE
RETURN return_value;
END;
$return_value$ LANGUAGE plpgsql;
I would like to understand why this spawns the error
ERROR: unrecognized configuration parameter "return_value"
Upvotes: 0
Views: 104
Reputation:
As documented in the manual the assignment of values to variables is done using :=
in PL/pgSQL
CREATE OR REPLACE FUNCTION test()
RETURNS BOOLEAN
AS
$return_value$
DECLARE
return_value BOOLEAN;
BEGIN
return_value := TRUE; --<< you are also missing a ; at the end
RETURN return_value;
END;
$return_value$
LANGUAGE plpgsql;
There is also an SQL statement SET
, but it sets database configuration parameters rather than assigning PL/pgSQL variables, which explains the error message.
Upvotes: 1