I have written a function which takes parameter called id that gets integer. When function is called, it returns specific user's info that is user_id, name and password.
If specific user does not exist, function returns the last user of the table.
The function is:
create function getUser(id int) returns table(user_id int, name varchar, password varchar) language plpgsql as $$ declare info users%rowtype; begin select * from users into info where user_id = id; if not found then raise warning 'such user does not exist'; select * from users into info where user_id = MAX(users.user_id); end if; return info; end; $$; but the result is:
RETURN cannot have a parameter in function returning set LINE 27: return info; ^ HINT: Use RETURN NEXT or RETURN QUERY. users table consists of such columns and rows:
user_id | name | password | I don't know where i made mistake. What should I do to solve this?
return query. postgresql.org/docs/current/…