Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group