Re: behaviour of LENGTH() in postgresql v. 8 - Mailing list pgsql-novice

From Tom Lane
Subject Re: behaviour of LENGTH() in postgresql v. 8
Date
Msg-id 29795.1099089110@sss.pgh.pa.us
Whole thread Raw
In response to behaviour of LENGTH() in postgresql v. 8  ("Marcus Andree S. Magalhaes" <marcus.magalhaes@vlinfo.com.br>)
Responses Re: behaviour of LENGTH() in postgresql v. 8
List pgsql-novice
"Marcus Andree S. Magalhaes" <marcus.magalhaes@vlinfo.com.br> writes:
> If I understand correctly, this will lead to the following situation:
>       CHAR_LENGTH('ABCD') == CHAR_LENGTH('ABCD    ') == 4
> This will definitely break some of our applications.

If you think trailing spaces are semantically significant, you should be
using varchar or text fields to store them.  In CHAR(n) fields they are
not significant, and we're doing our best to make that interpretation
consistent across all operations.

Just for the record, I get this with CVS tip:

regression=# select CHAR_LENGTH('ABCD    ');
 char_length
-------------
           8
(1 row)

regression=# select CHAR_LENGTH('ABCD    '::text);
 char_length
-------------
           8
(1 row)

regression=# select CHAR_LENGTH('ABCD    '::varchar);
 char_length
-------------
           8
(1 row)

regression=# select CHAR_LENGTH('ABCD    '::char(8));
 char_length
-------------
           4
(1 row)

(the first and second cases are in fact the same)

            regards, tom lane

pgsql-novice by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: behaviour of LENGTH() in postgresql v. 8
Next
From: "Marcus Andree S. Magalhaes"
Date:
Subject: Re: behaviour of LENGTH() in postgresql v. 8