Re: question about array indexing

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Szymon Lipiński <mabewlun(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: question about array indexing
Date: 2019-11-04 16:15:36
Message-ID: CAHyXU0wj80g8tKtOcv8HExnzhTeyWaFMuaN_Jyz9hk2k57Pcwg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Nov 4, 2019 at 10:05 AM Szymon Lipiński <mabewlun(at)gmail(dot)com> wrote:
>
> Hey,
> I'm wondering if this isn't a bug somewhere in the parser. I had to add additional parenthesis around the regexp_split_to_array.
>
>
> $ with x as (select 'a b c' a)
> select
> regexp_split_to_array(a, ' ')
> from x;
>
> regexp_split_to_array
> -----------------------
> {a,b,c}
> (1 row)
>
> $ with x as (select 'a b c' a)
> select
> regexp_split_to_array(a, ' ')[1]
> from x;
>
> ERROR: syntax error at or near "["
> LINE 3: regexp_split_to_array(a, ' ')[1]
> ^
> $ with x as (select 'a b c' a)
> select
> (regexp_split_to_array(a, ' '))[1]
> from x;
> regexp_split_to_array
> -----------------------
> a
> (1 row)

It's always been that way. You also have to wrap function column expansions:
select (func()).*

I don't know the exact technical reason why that's required, but my
money is on precedence related problems.

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2019-11-04 17:01:46 Re: Issues with PAM : log that it failed, whether it actually failed or not
Previous Message Stephen Frost 2019-11-04 16:06:44 Re: v12 and pg_restore -f-