I'm new to PostgreSQL, coming from SQL server and I'm having trouble creating a function and/or procedure. First of all, may I just clarify that the only difference between a function and a procedure is indeed the support for transactions?
Now going back to my problem, I want a simple func/proc that returns the current connected user. Not using it anyhow, so any other example would work, it's only for learing the syntax as pgsql is different from t-sql. Here is my code, which I took from a tutorials website:
CREATE OR REPLACE FUNCTION dev.get_user()
RETURNS VARCHAR AS $user$
DECLARE
$user$ VARCHAR;
BEGIN
SELECT current_user AS user;
RETURN user;
END;
$user$ LANGUAGE plpgsql;
I'm getting this and I don't know why:
ERROR: syntax error at or near "VARCHAR"
LINE 4: $user$ VARCHAR;
If I remove line 4, it creates it successfully, but when I run it, it returns this error:
ERROR: query has no destination for result data
HINT: If you want to discard the results of a SELECT, use PERFORM instead.
I'm on pgsql 12.3, if it makes any difference. Thank you.