Re: Why format() adds double quote? - Mailing list pgsql-hackers

From Tatsuo Ishii
Subject Re: Why format() adds double quote?
Date
Msg-id 20160126.162911.1679384760105448455.t-ishii@sraoss.co.jp
Whole thread Raw
In response to Re: Why format() adds double quote?  ("Dickson S. Guedes" <listas@guedesoft.net>)
Responses Re: Why format() adds double quote?
Re: Why format() adds double quote?
List pgsql-hackers
> 2016-01-24 8:04 GMT-02:00 Tatsuo Ishii <ishii@postgresql.org>:
>>> On Wed, Jan 20, 2016 at 4:20 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
>>>>> If we would go this way, question is if we should back patch this or
>>>>> not since the patch apparently changes the existing
>>>>> behaviors. Comments?  I would think we should not.
>>>>
>>>> I am sure, so we should not backport this change. This can breaks customer
>>>> regress tests - and the current behave isn't 100% correct, but it is safe.
>>>
>>> Quite.  This is not a bug fix.  It's a behavior change, perhaps for the better.
>>
>> Added to the commitfest 2016-03.
> 
> Hi,
> 
> I gone ahead a little and tested this patch and it works like was
> proposed, I agree that it's not a bug fix but a new behavior so -1 for
> backport.

IMO, it's a bug or at least an inconsistency but I admit it's too late
to back patch to existing stable branches.

> While applying patch against master
> (1129c2b0ad2732f301f696ae2cf98fb063a4c1f8) it offsets two hunks.
> 
> Since format() has regression tests I suggest that one should be added
> to cover this. 

I don't think it's doable. The test requires to handle multiple
database encodings. The regression test framework handles only one
database encoding. Probably adding to the existing mb test is the
easiest.

> It could worth to add the new behavior to the docs,
> since there no explicit example for %I.

> I performed the follow tests that works as expected using some Portuguese words:

I assume you used UTF-8 encoding database.
Great.

> postgres=# create table test (nome varchar, endereço text, "UF"
> varchar(2), título varchar);
> CREATE TABLE
> Time: 80,769 ms
> postgres=# select format('%I', attname) from pg_attribute join
> pg_class on (attrelid = oid) where relname = 'test';
>   format
> ----------
>  "UF"
>  cmax
>  cmin
>  ctid
>  endereço
>  nome
>  tableoid
>  título
>  xmax
>  xmin
> (10 rows)
> 
> Time: 1,728 ms
> postgres=# select format('%I', 'endereco');
>   format
> ----------
>  endereco
> (1 row)
> 
> Time: 0,098 ms
> postgres=# select format('%I', 'endereço');
>   format
> ----------
>  endereço
> (1 row)
> 
> Time: 0,088 ms
> postgres=# select format('%I', 'あああ');
>  format
> --------
>  あああ
> (1 row)
> 
> Time: 0,072 ms
> postgres=# select format('%I', 'título');
>  format
> --------
>  título
> (1 row)
> 
> Time: 0,051 ms
> postgres=# select format('%I', 'título e');
>    format
> ------------
>  "título e"
> (1 row)
> 
> Time: 0,051 ms
> postgres=# select format('%I', 'título_e');
>   format
> ----------
>  título_e
> (1 row)
> 
> Time: 0,051 ms
> postgres=# select format('%I', '_título');
>  format
> ---------
>  _título
> (1 row)
> 
> Time: 0,047 ms
> postgres=# select format('%I', '1_título');
>    format
> ------------
>  "1_título"
> (1 row)
> 
> Time: 0,046 ms
> 
> 
> Thank you for this!
> 
> 
> Best regards,
> -- 
> Dickson S. Guedes
> mail/xmpp: guedes@guedesoft.net - skype: guediz
> http://github.com/guedes - http://guedesoft.net
> http://www.postgresql.org.br

pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: proposal: PL/Pythonu - function ereport
Next
From: Andres Freund
Date:
Subject: Re: Releasing in September