composite type cast and select statement - Mailing list pgsql-sql

From Yura Gal
Subject composite type cast and select statement
Date
Msg-id 3b6c69d80808051030p1d9ea523ma1b85f70446c6396@mail.gmail.com
Whole thread Raw
List pgsql-sql
I would like to get effect of selecting table record when construct a
composite type.

CREATE TYPE "chains"."foo" AS (id INTEGER,bar INTEGER
);

CREATE OR REPLACE FUNCTION construct_foo(INTEGER,INTEGER) RETURNS
chains.foo AS $$
DECLAREf chains.foo;
BEGINf.id := $1;f.bar := $2;RETURN f;
END;
$$ LANGUAGE 'plpgsql';

SELECT * FROM construct_foo(10,20);
id    bar
10    20

However I do not like idea to write a function similar to
"construct_foo" for each composite type I have.
I tried to solve this problem through selection of composite type
literal input, and I got following:

SELECT '(10,20)'::chains.foo;
foo
(10,20)

The only query I got desirable result is:
SELECT (t.foo).* FROM(SELECT '(10,20)'::chains.foo) t;
id    bar
10    20

Is there a way to obtain the same result without use of the nested query?

--
Best regards. Yuri.
mailto: yuragal@gmail.com


pgsql-sql by date:

Previous
From: Ryan Wallace
Date:
Subject: Single Quote in tsquery
Next
From: "Richard Broersma"
Date:
Subject: Re: more than 1000 connections