|
Home > Archive > PostgreSQL Bugs > November 2005 > Bug on CHARACTER(n) ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Bug on CHARACTER(n) ?
|
|
| Stefano Reksten 2005-11-28, 11:24 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@postgresql
.org so that your
message can get through to the mailing list cleanly
| |
| Pawel Bernat 2005-11-28, 11:24 am |
| 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 ...
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
| |
| Tom Lane 2005-11-28, 11:24 am |
| 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
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
| |
| Pawel Bernat 2005-11-29, 11:24 am |
| 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 ...
---------------------------(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
|
|
|
|
|