Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

row->ARRAY or row->table casting?



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 :)



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group