From: b.wood@niwa.co.nz
To: pgsql-bugs@postgresql.org
Subject: BUG #11875: char() not behaving as documented
Date: Tue, 04 Nov 2014 19:55:17 +0000
Message-ID: <20141104195517.26930.71023@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 11875
Logged by: Brent Wood
Email address: b.wood@niwa.co.nz
PostgreSQL version: 9.2.0
Operating system: Linux
Description:
According to the docs
http://www.postgresql.org/docs/9.3/static/datatype-character.html)(:
" If the string to be stored is shorter than the declared length, values of
type character will be space-padded; values of type character varying will
simply store the shorter string."
Yet chars are not being padded, in fact they lose trailing spaces which are
retained by varchars. They also return length()'s less than the defined
length... which should not be the case for a padded string as defined in the
documentation.
fish=# create table test(var3 varchar(3),cha3 char(3));
CREATE TABLE
fish=# insert into test values('1','1');
INSERT 0 1
fish=# insert into test values('2 ','2 '); -- one space
INSERT 0 1
fish=# insert into test values('3 ','3 '); --two spaces
INSERT 0 1
fish=# select var3||':' as var3, cha3||':' as char3 from test;
var3 | char3
------+-------
1: | 1:
2 : | 2:
3 : | 3:
(3 rows)
test=# select length(var3) as v_lgth, length(cha3) as c_length from test;
v_lgth | c_length
--------+----------
1 | 1
2 | 1
3 | 1
So, in summary, varchar stores whatever feed to it and keeps trailing spaces
to max length, char type will trim off trailing spaces, and store a string
shorter than the specified length.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: b.wood@niwa.co.nz
Subject: Re: BUG #11875: char() not behaving as documented
In-Reply-To: <20141104195517.26930.71023@wrigleys.postgresql.org>
References: <20141104195517.26930.71023@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox