I'm trying to create a function PostgreSQL to check if a user exist in a table users by creating a function who return a JSON variable.
CREATE OR REPLACE FUNCTION login( uname character varying(55),pswd character varying(55))
RETURNS json AS
$$
DECLARE
msg json ;
BEGIN
IF ((SELECT COUNT(*) FROM (SELECT * FROM users WHERE username=uname and password=pswd) AS row_count) =1)
THEN
msg="{ 'stat' : 'active' }";
RETURN msg;
ELSE
msg="{ 'stat' : 'inactive' }";
RETURN msg;
END IF;
END;
$$ LANGUAGE plpgsql;
But when I try to using it it's return me the following error: ERROR: column "{ 'stat' : 'inactive' }" does not exist