-- FUNCTION: sonex.current_account_get()

-- DROP FUNCTION IF EXISTS sonex.current_account_get();

CREATE OR REPLACE FUNCTION sonex.current_account_get(
	)
    RETURNS sonex.v_accounts
    LANGUAGE 'sql'
    COST 100
    VOLATILE SECURITY DEFINER PARALLEL UNSAFE
AS $BODY$
SELECT *
FROM sonex.v_accounts
WHERE account_name = session_user
LIMIT 1;
$BODY$;

ALTER FUNCTION sonex.current_account_get()
    OWNER TO postgres;

GRANT EXECUTE ON FUNCTION sonex.current_account_get() TO account WITH GRANT OPTION;

GRANT EXECUTE ON FUNCTION sonex.current_account_get() TO postgres WITH GRANT OPTION;

REVOKE ALL ON FUNCTION sonex.current_account_get() FROM PUBLIC;
