question about array indexing

From: Szymon Lipiński <mabewlun(at)gmail(dot)com>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: question about array indexing
Date: 2019-11-04 16:05:14
Message-ID: CAFjNrYspXQpG4H-JHgPzQ3uV=8QytF-Bo1oHZidDVSEozixj_g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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)

regards,
Szymon

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephen Frost 2019-11-04 16:06:44 Re: v12 and pg_restore -f-
Previous Message Euler Taveira 2019-11-04 15:14:09 Re: v12 and pg_restore -f-