Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kTvIg-0001yK-MC for pgsql-general@arkaria.postgresql.org; Sat, 17 Oct 2020 23:07:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kTvIf-0004Zl-Di for pgsql-general@arkaria.postgresql.org; Sat, 17 Oct 2020 23:07:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kTvIf-0004Ze-5v for pgsql-general@lists.postgresql.org; Sat, 17 Oct 2020 23:07:45 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kTvIc-0000zp-SN for pgsql-general@lists.postgresql.org; Sat, 17 Oct 2020 23:07:44 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 09HN7ZQW145481; Sat, 17 Oct 2020 19:07:35 -0400 From: Tom Lane To: "Peter J. Holzer" cc: pgsql-general@lists.postgresql.org Subject: Re: print formated special characteres In-reply-to: <20201017224437.GA14168@hjp.at> References: <20201017185136.GA11747@c720-r342378> <20201017224437.GA14168@hjp.at> Comments: In-reply-to "Peter J. Holzer" message dated "Sun, 18 Oct 2020 00:44:37 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <145479.1602976055.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 17 Oct 2020 19:07:35 -0400 Message-ID: <145480.1602976055@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "Peter J. Holzer" writes: > On 2020-10-17 20:51:36 +0200, Matthias Apitz wrote: >> El d=C3=ADa s=C3=A1bado, octubre 17, 2020 a las 03:37:46p. m. -0300, Ce= lso Lorenzetti escribi=C3=B3: >>> elog(INFO, "\n%-10s Fim\n%-10s Fim\n", "Vari=C3=A1vel", "Variavel"); > Which programming language is this? PL/pgSQL? Looks like C in the backend. >> The second test (changing the accented char '=C3=A1' by 'X'), shows tha= t the >> problem/bug is a) more generic, not only in PostgreSQL and b) has todo >> with being the UTF-8 char '=C3=A1' a two byte char, while 'X' is only o= ne >> byte. > Yes, determining how much space a UTF-8 sequence occupies on screen is > surprisingly hard. I'm not sure what the C standard says about that. But > these days I would expect any programming language to get it right at > least for the simple cases. Our version of snprintf intentionally counts bytes not characters, so that it does not have to make assumptions about what encoding the given string uses. It's somewhat unclear whether the C/POSIX standard mandates either of these interpretations. The GNU implementation of snprintf tries to count characters. But in the cases where that's mattered to us at all, it's generally been the wrong thing, because glibc didn't necessarily know the encoding to use. That's one reason why we stopped relying on libc's snprintf. The way to get this to work as Celso wishes would be to count characters and then do his own arithmetic about how much padding to add. regards, tom lane