Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f17Ro-0001iz-Lg for pgsql-general@arkaria.postgresql.org; Wed, 28 Mar 2018 09:32:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f17Rn-0002id-Lp for pgsql-general@arkaria.postgresql.org; Wed, 28 Mar 2018 09:32:47 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f17Rn-0002iU-A1 for pgsql-general@lists.postgresql.org; Wed, 28 Mar 2018 09:32:47 +0000 Received: from mail.i-mark.de ([188.138.104.222]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f17Rj-0000Qz-Q5 for pgsql-general@lists.postgresql.org; Wed, 28 Mar 2018 09:32:46 +0000 Received: from [192.168.178.20] (unknown [185.38.49.16]) by mail.i-mark.de (Postfix) with ESMTPSA id 87774158017F for ; Wed, 28 Mar 2018 11:32:37 +0200 (CEST) Authentication-Results: loft7616.startdedicated.de; spf=pass (sender IP is 185.38.49.16) smtp.mailfrom=andreas@a-kretschmer.de smtp.helo=[192.168.178.20] Received-SPF: pass (loft7616.startdedicated.de: connection is authenticated) Subject: Re: Fixed chars To: pgsql-general@lists.postgresql.org References: <94af194d-9614-781d-9458-dfda05c86449@nbsgroup.it> From: Andreas Kretschmer Message-ID: Date: Wed, 28 Mar 2018 11:32:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <94af194d-9614-781d-9458-dfda05c86449@nbsgroup.it> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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