Re: Fixed chars - Mailing list pgsql-general

From Andreas Kretschmer
Subject Re: Fixed chars
Date
Msg-id f692c85d-4c64-d94b-ed35-cf2b0799bf0e@a-kretschmer.de
Whole thread Raw
In response to Fixed chars  (Enrico Pirozzi <e.pirozzi@nbsgroup.it>)
Responses Re: Fixed chars  (Enrico Pirozzi <e.pirozzi@nbsgroup.it>)
List pgsql-general

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



pgsql-general by date:

Previous
From: Enrico Pirozzi
Date:
Subject: Fixed chars
Next
From: Enrico Pirozzi
Date:
Subject: Re: Fixed chars