row->ARRAY or row->table casting?

From: Nico Sabbi <nsabbi(at)officinedigitali(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: row->ARRAY or row->table casting?
Date: 2007-09-28 15:37:38
Message-ID: 46FD1FC2.4090304@officinedigitali.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
is there any way to cast a generic row to an array or to a table type?

The example is trivial, but it explains what I'm trying to do:

nb1=# select * from tab1;
a | t
---+---
1 | a
2 | b
3 | c
(3 rows)

nb1=# select r from (select row(tab1.*) as r from tab1)x;
r
-------
(1,a)
(2,b)
(3,c)
(3 rows)

nb1=# select r[1] from (select row(tab1.*) as r from tab1)x;
ERROR: cannot subscript type record because it is not an array

nb1=# select (r::tab1).a from (select row(tab1.*) as r from tab1)x;
ERROR: cannot cast type record to tab1

The real use case is much more complex than this example of course :)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mike Charnoky 2007-09-28 15:56:46 more problems with count(*) on large table
Previous Message Ted Byers 2007-09-28 15:28:50 Re: How to avoid: 9.50184e+06