I have the following PostgreSQL function which returns multiple columns from a table:
CREATE OR REPLACE FUNCTION userbyid(id integer)
RETURNS TABLE(id int, username character varying(30), email character varying(254), last_login timestamp with time zone) AS
$$
SELECT
id,
username,
email,
last_login
FROM
auth_user
WHERE
id = $1;
$$
LANGUAGE 'sql';
The result it returns looks like this:
userbyid
--------------------------------------------------------------
(2, smith, [email protected], "2017-06-04 19:47:49.472259+00")
Is it possible to display the output with the correct column headers, something like this:
id username email last_login
--------------------------------------------------------------
2 smith [email protected] 2017-06-04
I'm looking at the CREATE FUNCTION document page and it isn't clear how to do this. I've also searched online and haven't seen an article that discusses this.
You need to format PostgreSQL to show the colum headers; Set it with:
\t
this can be seen in PSQL help\?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With