Bug on CHARACTER(n) ?

Started by Stefano Rekstenover 20 years ago4 messagesbugs
Jump to latest
#1Stefano Reksten
sreksten@sdb.it

Hello list,
maybe I am missing something. Look at this:

CREATE TABLE test (name character(10));

INSERT INTO test VALUES ('test');

SELECT '<' || name || '>' FROM test;

?column?
----------
<test>

SELECT length(name), name from test;
length | name
--------+------------
4 | test

Should not a char(10) insert 6 padding spaces? Or am I missing something
like an update in the SQL standard?
Sorry if this is an already known issue, I had no time lately to check the
bugs mailing list.

Ciao,
Stefano

#2Pawel Bernat
asm@asm.flynet.pl
In reply to: Stefano Reksten (#1)
Re: Bug on CHARACTER(n) ?

On Mon, Nov 28, 2005 at 05:49:02PM +0100, Stefano Reksten wrote:

Should not a char(10) insert 6 padding spaces? Or am I missing something
like an update in the SQL standard?

Use char_length(string).

regards
--
Paweďż˝ Bernat; uselessness' lover;
select'<asm'||chr(64)||'asm'||'.'||'flynet'||chr(46)||'pl>'as email;
Slowly and surely the unix crept up on the Nintendo user ...

#3Pawel Bernat
asm@vlo.olsztyn.pl
In reply to: Stefano Reksten (#1)
Re: Bug on CHARACTER(n) ?

On Mon, Nov 28, 2005 at 05:49:02PM +0100, Stefano Reksten wrote:

Should not a char(10) insert 6 padding spaces? Or am I missing something
like an update in the SQL standard?

char_length()

regards
--
Paweďż˝ Bernat; uselessness' lover;
select'<asm'||chr(64)||'asm'||'.'||'flynet'||chr(46)||'pl>'as email;
Slowly and surely the unix crept up on the Nintendo user ...

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Stefano Reksten (#1)
Re: Bug on CHARACTER(n) ?

Stefano Reksten <sreksten@sdb.it> writes:

SELECT length(name), name from test;
length | name
--------+------------
4 | test

Should not a char(10) insert 6 padding spaces?

It does, as you can see in the above output; but the padding spaces are
considered semantically insignificant and are therefore ignored by
length() and by concatenation. If you think that trailing spaces are
meaningful data, then use varchar(n) or text.

regards, tom lane