pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: 曾满 <zengman@halodbtech.com>
To: Erik Wienhold <ewie@ewie.name>
To: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
Subject: Re: Re: BUG #18632: Whether you need to consider modifying the array's handling of delimiters?
Date: Wed, 25 Sep 2024 17:16:51 +0800
Message-ID: <tencent_7DAA8DBD2F7167F20912BFB6@qq.com> (raw)

(Sorry, there was a garbled situation in the last email)
Thank you. I know that the way you said can be handled normally.


postgres=# SELECT ('{''a-3'',''a,3''}'::varchar[]);
    varchar    
---------------
 {'a-3','a,3'}
(1 row)


I wonder if we need to modify array_in so that ''a,3'' and ''a-3'' behave the same and have a uniform style.
Would it be better?


postgres=# SELECT ('{''a-3'',''a,3''}'::varchar[])[1];
 varchar 
---------
 'a-3'
(1 row)


postgres=# SELECT ('{''a-3'',''a,3''}'::varchar[])[2];
 varchar 
---------
 'a
(1 row)




                    Erik Wienhold<ewie@ewie.name> 在 2024年9月25日 周三 16:32 写道:

On 2024-09-25 09:57 +0200, PG Bug reporting form wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      18632
> Logged by:          Man Zeng
> Email address:      zengman@halodbtech.com
> PostgreSQL version: 14.10
> Operating system:   centos-8
> Description:        
> 
> Hi, I found a problem with array separator handling.
> The current handling of delimiters is not quite as expected (not very
> flexible).
> The test SQL and results are shown below.
> 
> [postgres@halo-centos-8-release ~]$ psql
> psql (14.10)
> Type "help" for help.
> 
> postgres=# CREATE OR REPLACE FUNCTION arrayfunc() 
> postgres-# RETURNS _varchar 
> postgres-# AS $$ 
> postgres$#   SELECT '{''a,3'',''b'',''c''}'::_varchar; 
> postgres$# $$ LANGUAGE SQL;
> CREATE FUNCTION
> postgres=# -- array cstring
> postgres=# SELECT arrayfunc();
>     arrayfunc    
> -----------------
>  {'a,3','b','c'}
> (1 row)
> 
> postgres=# -- length is 4
> postgres=# SELECT array_length(arrayfunc(), 1); 
>  array_length 
> --------------
>             4
> (1 row)
> 
> postgres=# -- first element
> postgres=# SELECT (arrayfunc())[1];
>  arrayfunc 
> -----------
>  'a
> (1 row)
> 
> postgres=# -- second element
> postgres=# SELECT (arrayfunc())[2];
>  arrayfunc 
> -----------
>  3'
> (1 row)

You need to double-quote elements that contain the separator:

    SELECT '{"''a,3''",''b'',''c''}'::varchar[];

That's also documented in the first paragraph of
https://www.postgresql.org/docs/current/arrays.html#ARRAYS-INPUT

So, not a bug.

> postgres=# -- other
> postgres=# SELECT (arrayfunc())[3];
>  arrayfunc 
> -----------
>  'b'
> (1 row)
> 
> postgres=# SELECT (arrayfunc())[4];
>  arrayfunc 
> -----------
>  'c'
> (1 row)
> 
> postgres=# -- The following SQL tests are as expected
> postgres=# CREATE OR REPLACE FUNCTION arrayfunc2() 
> postgres-# RETURNS _varchar 
> postgres-# AS $$ 
> postgres$#   SELECT '{''a-3'',''b'',''c''}'::_varchar; 
> postgres$# $$ LANGUAGE SQL;
> CREATE FUNCTION
> postgres=# -- array cstring
> postgres=# SELECT arrayfunc2();
>    arrayfunc2    
> -----------------
>  {'a-3','b','c'}
> (1 row)
> 
> postgres=# -- length is 3
> postgres=# SELECT array_length(arrayfunc2(), 1); 
>  array_length 
> --------------
>             3
> (1 row)
> 
> postgres=# -- first element
> postgres=# SELECT (arrayfunc2())[1];
>  arrayfunc2 
> ------------
>  'a-3'
> (1 row)
> 
> So should we consider modifying "array_in" to enhance the handling of
> separators to be more consistent with people's expectations?
> 

-- 
Erik

view thread (6+ messages)  latest in thread

Message-ID: <tencent_7DAA8DBD2F7167F20912BFB6@qq.com>
Permalink:  ../tencent_7DAA8DBD2F7167F20912BFB6@qq.com/
Also on:    postgresql.org/message-id/tencent_7DAA8DBD2F7167F20912BFB6@qq.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-bugs@postgresql.org
  Cc: zengman@halodbtech.com, ewie@ewie.name, pgsql-bugs@lists.postgresql.org
  Subject: Re: Re: BUG #18632: Whether you need to consider modifying the array's handling of delimiters?
  In-Reply-To: <tencent_7DAA8DBD2F7167F20912BFB6@qq.com>

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

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