I wrote the following function:
-- Authenticate: Get session_id with user_id
CREATE OR REPLACE FUNCTION sessions_get(bigint) RETURNS SETOF char(32) AS
$$
SELECT strip_hyphens(id) as id FROM sessions WHERE user_id = $1;
$$
LANGUAGE SQL;
I want to be able to run the query
SELECT sessions_get(1)
to get the session ID with user ID 1. And, I want the name of the column returned to beid
.Is that possible? Or, would the query have to be
SELECT * FROM sessions_get(1)
? In that case, it'd be shorter to just writeSELECT sessions_get(1) as id
. Which is better?Can I remove
SETOF
since I know this function will always return 0 or 1 rows? I know this becauseuser_id
is the primary key of thesessions
table.