composite type cast and select statement

Поиск
Список
Период
Сортировка
От Yura Gal
Тема composite type cast and select statement
Дата
Msg-id 3b6c69d80808051030p1d9ea523ma1b85f70446c6396@mail.gmail.com
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: Ryan Wallace
Дата:
Сообщение: Single Quote in tsquery
Следующее
От: "Richard Broersma"
Дата:
Сообщение: Re: more than 1000 connections