Re: array problem with double quotes

Joe Conway <[email protected]> Tue, 16 Oct 2018 08:36:44 -0400
Newsgroups gmane.comp.db.postgresql.sql
Message-ID <[email protected]>
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