Re: [PATCHES] [BUGS] casting strings to multidimensional arrays yields

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Hackers (PostgreSQL)" <pgsql-hackers(at)postgresql(dot)org>, Kris Jurka <books(at)ejurka(dot)com>
Subject: Re: [PATCHES] [BUGS] casting strings to multidimensional arrays yields
Date: 2004-08-07 01:50:01
Message-ID: 41143549.4030405@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Tom Lane wrote:
> I think that suppressing unquoted trailing whitespace is probably
> reasonable. I'm much less enthusiastic about rejecting unquoted
> embedded whitespace, though. I think that's significantly likely
> to break apps, and it doesn't seem like it's really needed to have
> sane behavior. The leading/trailing whitespace asymmetry is just
> weird, but it doesn't follow that embedded whitespace is weird.
>
> If we are going to make such changes, 8.0 is the right time to do it.

The attached patch suppresses trailing whitespace, but allows embedded
whitespace in unquoted elements as discussed above. It also rejects some
previously accepted cases that were just too strange to be correct:

-- Postgres 8.0, with the patch
-- none of these should be accepted
select '{{1,{2}},{2,3}}'::text[];
ERROR: malformed array literal: "{{1,{2}},{2,3}}"
select '{{},{}}'::text[];
ERROR: malformed array literal: "{{},{}}"
select '{{1,2},\\{2,3}}'::text[];
ERROR: malformed array literal: "{{1,2},\{2,3}}"
select '{{"1 2" x},{3}}'::text[];
ERROR: malformed array literal: "{{"1 2" x},{3}}"

The third case above actually does get an ERROR in 7.4 but it looks
suspicious itself:

-- in Postgres 7.4
select '{{1,2},\\{2,3}}'::text[];
ERROR: malformed array literal: "{{1"

More examples:

-- Postgres 8.0, with the patch
-- all of these should be accepted
select '{}'::text[];
text
------
{}
(1 row)

select '{0 second ,0 second}'::interval[];
interval
---------------------
{00:00:00,00:00:00}
(1 row)

select '{ { "," } , { 3 } }'::text[];
text
-------------
{{","},{3}}
(1 row)

select ' { { " 0 second " , 0 second } }'::text[];
text
-------------------------------
{{" 0 second ","0 second"}}
(1 row)

If there are no objections, I'll update the docs and commit tomorrow
sometime.

Thanks,

Joe

Attachment Content-Type Size
array-fixes-state.2.patch text/x-patch 8.2 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2004-08-07 02:56:49 Re: [PATCHES] [BUGS] casting strings to multidimensional arrays yields strange
Previous Message Tom Lane 2004-08-06 17:44:06 Re: Regex bug

Browse pgsql-hackers by date

  From Date Subject
Next Message Marc G. Fournier 2004-08-07 02:08:07 cvsweb down temporarily
Previous Message Bruce Momjian 2004-08-07 01:41:26 Re: parameter hints to the optimizer

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2004-08-07 02:15:23 Re: make fails if path has spaces
Previous Message Bruce Momjian 2004-08-07 01:04:34 Re: regexp_replace