Basic things like struct in C data types exist in all popular languages, and it is expected that the functions of these languages can also return struct ... And, by the principle of orthogonality, it is expected that you can access the returned itens structure.
PostgreSQL, however, did not provide access to struct itens FUNCTION ... RETURNS RECORD. It is right?
But programmers use PostgreSQL without complaint ... Is there a simple and intuitive workaround?
A similar question: PostgreSQL v9.X has a real "write array",
Typical Case Illustration
CREATE FUNCTION foo(int) RETURNS RECORD AS $$
SELECT $1 as a, 'Hello #'||$1 as b;
$$ LANGUAGE SQL;
SELECT foo(6);
Write access in SQL context :
SELECT (foo(6)).a;
WITH f AS (SELECT foo(6) as r) SELECT r.a FROM f;
PLpgSQL:
x:=(foo(6)).a y:=foo(6); x:=y.a? , PLpgSQL , , " ":
CREATE FUNCTION bar() RETURNS text AS $F$
DECLARE
tmp record;
s text;
BEGIN
tmp := foo(6);
s:=tmp.b;
RETURN s||'! '||tmp.a;
END;
$F$ LANGUAGE plpgsql IMMUTABLE;