Обсуждение: array problem with double quotes
Hi,
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)
returns
"v1";"v2"
"co";"{{ab},{"ab,da"}}"
where I wanted
"co";"{{ab},{ab,da}}"
to match with the result of an array_agg which returns {ab,da}
In my case I then can't have {ab,da} @> {"ab,da"}
Thanks,
Olivier
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