Re: array problem with double quotes

From: Joe Conway <mail(at)joeconway(dot)com>
To: Olivier Leprêtre <o(dot)lepretre(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: array problem with double quotes
Date: 2018-10-16 12:36:44
Message-ID: 2b14bcf3-a159-48e9-b5fd-eb3170331fc8@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 10/14/2018 09:40 AM, Olivier Leprêtre wrote:
> Is there a way to create arrays without postgres adding double quotes
> when there are commas ?
>
> select v1,v2 from (values ('co',array[['ab'],['ab,da']])) sub (v1,v2)

'ab,da' is a single string literal element in the above SQL

> where I wanted
>
> "co";"{{ab},{ab,da}}"

If you do this:
----
select v1,v2 from (values ('co',array[['ab'],['ab','da']])) sub (v1,v2);
ERROR: multidimensional arrays must have array expressions with
matching dimensions
----

Doesn't work because you have differing dimensions.

But these will work:
----
select v1,v2 from (values ('co',array[['ab',null],['ab','da']])) sub
(v1,v2);
v1 | v2
----+---------------------
co | {{ab,NULL},{ab,da}}
(1 row)
----
or
----
select v1,v2 from (values ('co','{{ab,null},{ab,da}}'::text[])) sub (v1,v2);
v1 | v2
----+---------------------
co | {{ab,NULL},{ab,da}}
(1 row)
----

HTH,

Joe

--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Graeme Gemmill 2018-11-03 17:40:53 Passinf field name
Previous Message Olivier Leprêtre 2018-10-14 13:40:33 array problem with double quotes