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 1f17lh-0002y2-1V for pgsql-general@arkaria.postgresql.org; Wed, 28 Mar 2018 09:53:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f17lf-0003oz-PA for pgsql-general@arkaria.postgresql.org; Wed, 28 Mar 2018 09:53:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f17lf-0003oq-HY for pgsql-general@lists.postgresql.org; Wed, 28 Mar 2018 09:53:19 +0000 Received: from mta1.ilger.com ([77.81.238.29]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f17lc-0008Ov-7V for pgsql-general@lists.postgresql.org; Wed, 28 Mar 2018 09:53:18 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mta1.ilger.com (Postfix) with ESMTP id F2C26428C8 for ; Wed, 28 Mar 2018 11:53:14 +0200 (CEST) X-Virus-Scanned: amavisd-new at mta1.ilger.com Received: from mta1.ilger.com ([127.0.0.1]) by localhost (mta1.ilger.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id KFs1_HWl2GjJ for ; Wed, 28 Mar 2018 11:53:14 +0200 (CEST) Received: from [172.18.4.138] (37-186-245-150.ip271.fastwebnet.it [37.186.245.150]) by mta1.ilger.com (Postfix) with ESMTPSA id D08B1425A4 for ; Wed, 28 Mar 2018 11:53:14 +0200 (CEST) Subject: Re: Fixed chars To: pgsql-general@lists.postgresql.org References: <94af194d-9614-781d-9458-dfda05c86449@nbsgroup.it> From: Enrico Pirozzi Message-ID: <7947a8b7-a908-3976-eb02-2810e480a267@nbsgroup.it> Date: Wed, 28 Mar 2018 11:53:17 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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