Re: how to convert relational column to array?

From: george young <gry(at)ll(dot)mit(dot)edu>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: how to convert relational column to array?
Date: 2005-12-19 17:12:11
Message-ID: 20051219121211.002f7e87.gry@ll.mit.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, 19 Dec 2005 09:54:49 -0700
Michael Fuhr <mike(at)fuhr(dot)org> threw this fish to the penguins:

> On Mon, Dec 19, 2005 at 11:06:12AM -0500, george young wrote:
> > create table new_tab(name text, id int, permits text[]);
> >
> > -- I insert one row per name:
> > insert into new_tab select distinct name,id,cast('{}' as text[]) from old_tab;
> >
> > Now I want to fold all the 'permits' values into the new permits arrays.
>
> In PostgreSQL 7.4 and later you can build an array from a select,
> so I think the following update should work (it did for me when I
> tested it):
>
> UPDATE new_tab SET permits = array(
> SELECT permits
> FROM old_tab
> WHERE old_tab.name = new_tab.name AND old_tab.id = new_tab.id
> );

That's exactly what I needed. Works great.

Thanks,
George
--
"Are the gods not just?" "Oh no, child.
What would become of us if they were?" (CSL)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ken Winter 2005-12-19 18:19:58 Re: Rule causes baffling error
Previous Message Michael Fuhr 2005-12-19 16:54:49 Re: how to convert relational column to array?