how to return a custom record with calculated data

A more typical use of a function would be something like this:

CREATE OR REPLACE FUNCTION NEW_RANK(original_rank)
  RETURNS int AS $$
BEGIN
  -- put add'l logic here if you want to do if/then statements, etc.
  RETURN original_rank + 5;
END;
$$ LANGUAGE plpgsql;

And then you invoke it like this:

select name, NEW_RANK(rank) from employees;

But note the function takes a single input and responds with a single output. That is typically how developers use SQL functions in my experience.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top