How to explode an array into multiple rows

From: Kevin Murphy <murphy2(at)speakeasy(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: How to explode an array into multiple rows
Date: 2005-08-02 20:34:44
Message-ID: 42EFD8E4.5060205@speakeasy.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'd like to do something like this:

select array_explode(array_col) from table1 where col2 = 'something';

where array_explode returns the elements of array_col unpacked onto
separate rows.

I tried creating a function returning a setof type, but postgresql
produces a "set-valued function called in context that cannot accept a
set" error. I've seen this error in the list archives, but I'm not sure
how to translate the simple cases discussed into this situation. I'm
sure it's something simple, but it's been eluding me.

Thanks,
Kevin Murphy

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bob Pawley 2005-08-02 20:36:22 Re: indexes are fucked
Previous Message Peter Wilson 2005-08-02 20:24:56 Re: feeding big script to psql