1

I've got a pretty simple function defined like so:

CREATE OR REPLACE FUNCTION create_new_order(....) RETURNS integer AS
$BODY$
BEGIN
    PERFORM add_points_to_usage(client_id_p, date_in_p, total_points_p);

INSERT INTO orders (...) VALUES (...)
    RETURNING ident;
END;
$BODY$ LANGUAGE plpgsql;

Where I'm struggling is how to actually RETURN the value stored in the ident field back via the RETURNING clause. I've tried setting the value to a variable but that either doesn't work or I'm just messing up the syntax.

1 Answer 1

1

You're missing the variable declaration, the INTO clause and the final RETURN:

CREATE OR REPLACE FUNCTION create_new_order(....) RETURNS integer AS
$BODY$
DECLARE
  var_ident int;
BEGIN
    PERFORM add_points_to_usage(client_id_p, date_in_p, total_points_p);
    INSERT INTO orders (...) VALUES (...)
       RETURNING ident INTO var_ident;
    RETURN var_ident;
END;
$BODY$ LANGUAGE plpgsql;
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.