dbTalk Databases Forums  

[BUGS] Bug on CHARACTER(n) ?

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] Bug on CHARACTER(n) ? in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stefano Reksten
 
Posts: n/a

Default [BUGS] Bug on CHARACTER(n) ? - 11-28-2005 , 10:49 AM






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


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly

Reply With Quote
  #2  
Old   
Pawel Bernat
 
Posts: n/a

Default Re: [BUGS] Bug on CHARACTER(n) ? - 11-28-2005 , 11:06 AM






On Mon, Nov 28, 2005 at 05:49:02PM +0100, Stefano Reksten wrote:
Quote:
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(4 6)||'pl>'as email;
Slowly and surely the unix crept up on the Nintendo user ...

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster


Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] Bug on CHARACTER(n) ? - 11-28-2005 , 11:20 AM



Stefano Reksten <sreksten (AT) sdb (DOT) it> writes:
Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq


Reply With Quote
  #4  
Old   
Pawel Bernat
 
Posts: n/a

Default Re: [BUGS] Bug on CHARACTER(n) ? - 11-29-2005 , 11:07 AM



On Mon, Nov 28, 2005 at 05:49:02PM +0100, Stefano Reksten wrote:
Quote:
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(4 6)||'pl>'as email;
Slowly and surely the unix crept up on the Nintendo user ...

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.