From: | "Yura Gal" <yuragal(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | composite type cast and select statement |
Date: | 2008-08-05 17:30:02 |
Message-ID: | 3b6c69d80808051030p1d9ea523ma1b85f70446c6396@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 $$
DECLARE
f chains.foo;
BEGIN
f.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(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Broersma | 2008-08-05 19:42:12 | Re: more than 1000 connections |
Previous Message | Ryan Wallace | 2008-08-05 17:19:02 | Single Quote in tsquery |