Here is a yet unanswered second part of an earlier question as a separate question:
CREATE OR REPLACE FUNCTION f1 (a1 INTEGER, a2 INTEGER)
RETURNS TABLE (c1 VARCHAR(20), c2 VARCHAR(20), c3 INTEGER, c4 VARCHAR(20), c5 VARCHAR(128))
AS $$
SELECT 'a'::VARCHAR(20), 'b'::VARCHAR(20), 1::INTEGER, 'c'::VARCHAR(20), 'd'::VARCHAR(128);
$$ LANGUAGE SQL;
This sample code is meant to create a function f1 that returns a table with a single row of 5 columns.
If I remove the casts from the SELECT statement, I get this error message:
Final statement returns unknown instead of character varying at column 1.
But are the casts really necessary? It would seem that the correct type VARCHAR(20) is known from RETURNS, so why is there no implicit cast of strings such as 'a'? Is there a better way to formulate such things in a concise way?