Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1stNRT-00FkNN-NG for pgsql-bugs@arkaria.postgresql.org; Wed, 25 Sep 2024 08:32:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1stNRT-005Ybi-1o for pgsql-bugs@arkaria.postgresql.org; Wed, 25 Sep 2024 08:32:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1stNRS-005YbS-Oj for pgsql-bugs@lists.postgresql.org; Wed, 25 Sep 2024 08:32:10 +0000 Received: from mout-u-107.mailbox.org ([2001:67c:2050:101:465::107]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1stNRP-000xad-PW for pgsql-bugs@lists.postgresql.org; Wed, 25 Sep 2024 08:32:09 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4XD92C011Sz9sT3; Wed, 25 Sep 2024 10:32:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ewie.name; s=MBO0001; t=1727253123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=H3Hh3OrGjHx2IKY/Lp/SdjEm4ZysllozbHdtfgLKWB0=; b=1zxGDRzs7e/BSzuPNLYgpU+XPaT0h1aI0T00/6rIpYnzZo1XZKbMSo9lzDe4sFh/wa4EfA ZKDcp9bSroCVk0L+cTtpoM9+p9ztfIPQeNVi7D9kY0C2iU2SFOlOy+l+eK8gSISGNsgQgJ y8TDeA04/OogICrWbMJl79OGN+BP8zkixZESgOmMtcM4sHg3rfTXut696XnwS/30oG6cRR ryqqLkw+XAUcW/kcNdNQ4JXRr8SsymrZDmLZayU3GwcZIQDuJS2nkdCYak2dx3HqKDLY9L rZjEawkpe5ALbuPeOIpJv+b1LeGsvvvlCHn0AjHUCkKqoOrHb0SRgkD9Id7hcg== Date: Wed, 25 Sep 2024 10:31:59 +0200 From: Erik Wienhold To: zengman@halodbtech.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18632: Whether you need to consider =?utf-8?Q?modifying_?= =?utf-8?Q?the_array's_handling_of_delimiters=EF=BC=9F?= Message-ID: <44d2a0a2-17ed-4ff9-9076-b05996f2d5a8@ewie.name> References: <18632-15cedd7d4154ea2a@postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <18632-15cedd7d4154ea2a@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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