agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedarray problem with double quotes
2+ messages / 2 participants
[nested] [flat]
* array problem with double quotes
@ 2018-10-14 13:40 Olivier Leprêtre <o.lepretre@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: Olivier Leprêtre @ 2018-10-14 13:40 UTC (permalink / raw)
To: pgsql-sql
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
---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: array problem with double quotes
@ 2018-10-16 12:36 Joe Conway <mail@joeconway.com>
parent: Olivier Leprêtre <o.lepretre@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Joe Conway @ 2018-10-16 12:36 UTC (permalink / raw)
To: Olivier Leprêtre <o.lepretre@gmail.com>; 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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2018-10-16 12:36 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-10-14 13:40 array problem with double quotes Olivier Leprêtre <o.lepretre@gmail.com>
2018-10-16 12:36 ` Joe Conway <mail@joeconway.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox