pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedFixed chars
3+ messages / 2 participants
[nested] [flat]
* Fixed chars
@ 2018-03-28 09:11 Enrico Pirozzi <e.pirozzi@nbsgroup.it>
0 siblings, 1 reply; 3+ messages in thread
From: Enrico Pirozzi @ 2018-03-28 09:11 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Hi , I've seen this strange thing.
sitedb=# create table test_tb(codice char(7));
CREATE TABLE
sitedb=# insert into test_tb values('pippo');
INSERT 0 1
sitedb=# select codice || 'a'::char(1),length(codice) from test_tb
?column? | length
----------+--------
pippoa | 5
(1 row)
On the official documentation
|character(/|n|/)|,|char(/|n|/)| fixed-length, blank padded
https://www.postgresql.org/docs/10/static/datatype-character.html
Can anyone help me?
Enrico
--
Enrico Pirozzi
NBS Group S.r.l.
via Val Tiberina 23/A
63074, San Benedetto del Tronto (AP)
Tel. 0735-7626201
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Fixed chars
@ 2018-03-28 09:32 Andreas Kretschmer <andreas@a-kretschmer.de>
parent: Enrico Pirozzi <e.pirozzi@nbsgroup.it>
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Kretschmer @ 2018-03-28 09:32 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Am 28.03.2018 um 11:11 schrieb Enrico Pirozzi:
> Hi , I've seen this strange thing.
>
> sitedb=# create table test_tb(codice char(7));
> CREATE TABLE
> sitedb=# insert into test_tb values('pippo');
> INSERT 0 1
> sitedb=# select codice || 'a'::char(1),length(codice) from test_tb
> ?column? | length
> ----------+--------
> pippoa | 5
> (1 row)
>
where is the problem? length() returns the number of chars in string,
and the string in codice is 5 chars long.
>
> On the official documentation
>
> |character(/|n|/)|,|char(/|n|/)| fixed-length, blank padded
>
> https://www.postgresql.org/docs/10/static/datatype-character.html
test=*# select length('12345'::char(10)), pg_column_size('12345'::char(10));
length | pg_column_size
--------+----------------
5 | 14
(1 Zeile)
helps that?
Regards, Andreas
--
2ndQuadrant - The PostgreSQL Support Company.
www.2ndQuadrant.com
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Fixed chars
@ 2018-03-28 09:53 Enrico Pirozzi <e.pirozzi@nbsgroup.it>
parent: Andreas Kretschmer <andreas@a-kretschmer.de>
0 siblings, 0 replies; 3+ messages in thread
From: Enrico Pirozzi @ 2018-03-28 09:53 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Resolved...my missing
Thanks
Enrico
https://www.postgresql.org/docs/10/static/datatype-character.html
"Values of type|character|are physically padded with spaces to the
specified width/|n|/, and are stored and displayed that way. However,
trailing spaces are treated as semantically insignificant and
disregarded when comparing two values of type|character|. In collations
where whitespace is significant, this behavior can produce unexpected
results; for example|SELECT 'a '::CHAR(2) collate "C" <
E'a\n'::CHAR(2)|returns true, even though|C|locale would consider a
space to be greater than a newline. Trailing spaces are removed when
converting a|character|value to one of the other string types. Note that
trailing spaces/are/semantically significant in|character
varying|and|text|values, and when using pattern matching, that
is|LIKE|and regular expressions."
Il 28/03/2018 11:32, Andreas Kretschmer ha scritto:
>
>
> Am 28.03.2018 um 11:11 schrieb Enrico Pirozzi:
>> Hi , I've seen this strange thing.
>>
>> sitedb=# create table test_tb(codice char(7));
>> CREATE TABLE
>> sitedb=# insert into test_tb values('pippo');
>> INSERT 0 1
>> sitedb=# select codice || 'a'::char(1),length(codice) from test_tb
>> ?column? | length
>> ----------+--------
>> pippoa | 5
>> (1 row)
>>
>
> where is the problem? length() returns the number of chars in string,
> and the string in codice is 5 chars long.
>
>
>>
>> On the official documentation
>>
>> |character(/|n|/)|,|char(/|n|/)| fixed-length, blank padded
>>
>> https://www.postgresql.org/docs/10/static/datatype-character.html
>
> test=*# select length('12345'::char(10)),
> pg_column_size('12345'::char(10));
> length | pg_column_size
> --------+----------------
> 5 | 14
> (1 Zeile)
>
>
>
> helps that?
>
>
> Regards, Andreas
>
--
Enrico Pirozzi
NBS Group S.r.l.
via Val Tiberina 23/A
63074, San Benedetto del Tronto (AP)
Tel. 0735-7626201
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2018-03-28 09:53 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-03-28 09:11 Fixed chars Enrico Pirozzi <e.pirozzi@nbsgroup.it>
2018-03-28 09:32 ` Andreas Kretschmer <andreas@a-kretschmer.de>
2018-03-28 09:53 ` Enrico Pirozzi <e.pirozzi@nbsgroup.it>
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