agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Joe Conway <mail@joeconway.com>
To: Olivier LeprĂȘtre <o.lepretre@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: array problem with double quotes
Date: Tue, 16 Oct 2018 08:36:44 -0400
Message-ID: <2b14bcf3-a159-48e9-b5fd-eb3170331fc8@joeconway.com> (raw)
In-Reply-To: <5bc34756.1c69fb81.22161.822d@mx.google.com>
References: <5bc34756.1c69fb81.22161.822d@mx.google.com>

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




view thread (2+ messages)

Message-ID: <2b14bcf3-a159-48e9-b5fd-eb3170331fc8@joeconway.com>
Permalink:  ../2b14bcf3-a159-48e9-b5fd-eb3170331fc8@joeconway.com/
Also on:    postgresql.org/message-id/2b14bcf3-a159-48e9-b5fd-eb3170331fc8@joeconway.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mail@joeconway.com, o.lepretre@gmail.com
  Subject: Re: array problem with double quotes
  In-Reply-To: <2b14bcf3-a159-48e9-b5fd-eb3170331fc8@joeconway.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox