From: | toreason(at)fastmail(dot)fm |
---|---|
To: | "Sam Mason" <sam(at)samason(dot)me(dot)uk> |
Cc: | "postgres general" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: [Q] parsing out String array |
Date: | 2009-08-16 09:55:08 |
Message-ID: | 1250416508.12585.1330064327@webmail.messagingengine.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thank you for your recommendation
I was able to get this to work
(using PG SQL parser to parse out two dimentional PG array
where the array data came from my client program instead of
a DB value)
select ('{{A,B,C},{D,E,F}}'::text[][])[i][j] from
generate_series(1, array_upper('{{A,B,C},{D,E,F}}'::text[][], 1)) i
cross join
generate_series(1, array_upper('{{A,B,C},{D,E,F}}'::text[][], 2)) j
On Sat, 15 Aug 2009 21:17 +0100, "Sam Mason" <sam(at)samason(dot)me(dot)uk> wrote:
> On Sat, Aug 15, 2009 at 01:41:12PM -0400, V S P wrote:
> > but running into a problem as I cannot typecast correctly
> >
> > select V[i][j]
> > FROM
> > (select '{{A,B,C},{D,E,F}}') as V
> > CROSS JOIN generate_series(1, 3) i
> > CROSS JOIN generate_series(1,2) j
> >
> > Does not work, because V is not an array (it is a string)
> > and I do not know where to put the typecast
> > ::text[][]
>
> Not sure what you tried, but the following does the "right" thing for
> me:
>
> SELECT ('{{A,B,C},{D,E,F}}'::text[])[1][1];
>
> The brackets are needed so that PG doesn't get confused between the type
> declaration and the array indexing.
>
> --
> Sam http://samason.me.uk/
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
--
Vlad P
author of C++ ORM http://github.com/vladp/CppOrm/tree/master
--
http://www.fastmail.fm - The professional email service
From | Date | Subject | |
---|---|---|---|
Next Message | Sam Mason | 2009-08-16 11:06:07 | Re: [Q] parsing out String array |
Previous Message | Madison Kelly | 2009-08-16 02:24:00 | A history procedure that prevents duplicate entries |