Re: behaviour of LENGTH() in postgresql v. 8

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Marcus Andree S(dot) Magalhaes" <marcus(dot)magalhaes(at)vlinfo(dot)com(dot)br>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: behaviour of LENGTH() in postgresql v. 8
Date: 2004-10-29 22:31:50
Message-ID: 29795.1099089110@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"Marcus Andree S. Magalhaes" <marcus(dot)magalhaes(at)vlinfo(dot)com(dot)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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Marcus Andree S. Magalhaes 2004-10-29 22:41:12 Re: behaviour of LENGTH() in postgresql v. 8
Previous Message Bruce Momjian 2004-10-29 22:17:03 Re: behaviour of LENGTH() in postgresql v. 8