0

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"

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.