From: Michael Fuhr <mike@fuhr.org>
To: george young <gry@ll.mit.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: how to convert relational column to array?
Date: Mon, 19 Dec 2005 09:54:49 -0700
Message-ID: <20051219165449.GA99764@winnie.fuhr.org> (raw)
In-Reply-To: <20051219110612.26de2268.gry@ll.mit.edu>
References: <20051219110612.26de2268.gry@ll.mit.edu>
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
);
--
Michael Fuhr
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mike@fuhr.org, gry@ll.mit.edu
Subject: Re: how to convert relational column to array?
In-Reply-To: <20051219165449.GA99764@winnie.fuhr.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox