Re: Dynamic multi dimensional arrays in SQL

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dane Foster <studdugie(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Dynamic multi dimensional arrays in SQL
Date: 2015-07-10 15:21:56
Message-ID: CAFj8pRCofhs-=at-3ySf9ehV-tZASKiSNQ8rry9Uw66ujH0kAw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

I am afraid, so this functionality is supported only in unreleased
PostgreSQL 9.5

postgres=# SELECT ARRAY(SELECT ARRAY[true::text,false::text] FROM
generate_series(1,2));
┌─────────────────────────────┐
│ array │
╞═════════════════════════════╡
│ {{true,false},{true,false}} │
└─────────────────────────────┘
(1 row)

It is one from new features there.

In previous versions you can to write own custom aggregate function.

Regards

Pavel Stehule

2015-07-10 16:52 GMT+02:00 Dane Foster <studdugie(at)gmail(dot)com>:

> Hello,
>
> I'm trying to dynamically construct a multi dimensional array where the
> outer most array's elements are binary arrays. My initial attempt was
> something to the effect of:
> SELECT ARRAY(SELECT ARRAY[true::text,false::text] FROM
> generate_series(1,2));
>
> My expectation is a result of the form: {{true,false},{true,false}}
>
> But it doesn't work. I get the following error instead: "could not find
> array type for data type text[]".
>
> The only way I've gotten it to work is to concatenate strings and
> explicitly cast the string to an array. It's ugly. I'm hoping the issue is
> that I'm doing something wrong and not that string concatenation or a
> procedural language are the only solutions.
>
> Any insight into what I'm doing wrong would be appreciated.
>
> Regards,
> ​
>
> Dane
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Robert DiFalco 2015-07-10 16:15:34 Bounded Zone Offset Query
Previous Message Dane Foster 2015-07-10 14:52:56 Dynamic multi dimensional arrays in SQL