I wrote that following function in Postgres, but I've got a problem: It always returns a Row. I mean, when no user does match the pair it returns a row with all columns empty.
Are there a way to make a function return 0(zero) rows when there's no result?
CREATE OR REPLACE FUNCTION find_user_by_credentials(email text, password text)
RETURNS
"User"
AS
$$
SELECT *
FROM "User" AS "U"
WHERE email = "U"."Email" AND "U"."Password" = md5(password || "U"."Salt")
;
$$
LANGUAGE SQL IMMUTABLE STRICT;
Interesting:
If I change the return type from "User" to
TABLE("Email" text,"GivenName" text,"ID" int8, "Password" text,"Salt" text)
It works as expected. But I really want use a "reference" to "User" because the maintance will be easier.
Thanks!