Re: [SQL] arrays

From: Karel Zak - Zakkr <zakkr(at)zf(dot)jcu(dot)cz>
To: Marcin Mazurek - Multinet SA - Poznan <m(dot)mazurek(at)multinet(dot)pl>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] arrays
Date: 1999-12-02 11:11:56
Message-ID: Pine.LNX.3.96.991202120526.29170C-100000@ara.zf.jcu.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Thu, 2 Dec 1999, Marcin Mazurek - Multinet SA - Poznan wrote:

> On Thu, 2 Dec 1999, Karel Zak - Zakkr wrote:
> > > I have a table: orders (id int, val INT4[][]);. The question is how to
> > > select in separate rows values from particular id?
> > > example:
> > > insert into orders values(1,'{{1,1},{1,4},{2,3}}');
> > > select val from orders where id=1; gives me:
> > > val
> > > -------------------
> > > {{1,2},{1,4},{2,3}}
> > If I good undertend you.. You want select values from a array in separate
> > rows. Hmm see:
> > select o.val[1][1] from orders o where id=1 UNION ALL select o.val[1][2]
> > from orders o where id=1;
> > val
> > ---
> > 1
> > 2
> > (2 rows)
> what i meant was:
> c1 c2
> 1 2
> 1 4
> 2 3
> how can i do this?
> mazek
>

Oh man, it is total equivalent:

select o.val[1][1] as c1, o.val[1][2] as c2 from orders o where id=1
UNION ALL
select o.val[2][1], o.val[2][2] from orders o where id=1
UNION ALL
select o.val[3][1], o.val[3][2] from orders o where id=1;
c1|c2
--+--
1| 2
1| 4
2| 3
(3 rows)

Karel

In response to

  • Re: [SQL] arrays at 1999-12-02 11:01:15 from Marcin Mazurek - Multinet SA - Poznan

Browse pgsql-sql by date

  From Date Subject
Next Message Virgilio Sanz 1999-12-02 15:16:24 PL/PgSQL: selects into strings
Previous Message Marcin Mazurek - Multinet SA - Poznan 1999-12-02 11:01:15 Re: [SQL] arrays