Skip site navigation (1) Skip section navigation (2)

Re: array variables

From: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: "Marcin Krawczyk" <jankes(dot)mk(at)gmail(dot)com>
Subject: Re: array variables
Date: 2008-11-13 09:39:03
Message-ID: 200811131139.03872.achill@matrix.gatewaynet.com (view raw or flat)
Thread:
Lists: pgsql-sql
Στις Thursday 13 November 2008 11:13:30 ο/η Marcin Krawczyk έγραψε:
> I know I can do one column like this :
> 
> a := ARRAY(SELECT id FROM idx);
> 
> but how about more than one ?
> Because if I try this :
> 
> a := ARRAY(SELECT id, p FROM idx);
> 
> I get
> ERROR: subquery must return only one column
> SQL state: 42601

how about smth like:
SELECT ARRAY[ARRAY(SELECT id FROM idx),ARRAY(SELECT p FROM idx)];

you will get 2 rows with "select count(*) from idx" columns each.
you can access it like
SELECT (ARRAY[ARRAY(SELECT id FROM idx),ARRAY(SELECT p FROM idx)])[i][j];
1<=i<=2
1<=j<=select count(*) from idx
> 
> regards
> mk
> 



-- 
Achilleas Mantzios

In response to

Responses

pgsql-sql by date

Next:From: Marcin KrawczykDate: 2008-11-13 09:44:01
Subject: Re: array variables
Previous:From: Pavel StehuleDate: 2008-11-13 09:30:43
Subject: Re: array variables

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group