Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJMVm-00044g-G0 for pgsql-general@arkaria.postgresql.org; Sat, 12 Oct 2019 18:53:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iJMUl-0005wr-9j for pgsql-general@arkaria.postgresql.org; Sat, 12 Oct 2019 18:52:03 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJMUk-0005wK-VE for pgsql-general@lists.postgresql.org; Sat, 12 Oct 2019 18:52:03 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJMUi-0004Tq-Bu for pgsql-general@lists.postgresql.org; Sat, 12 Oct 2019 18:52:02 +0000 Received: from [192.168.127.1] (port=51487 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1iJMUf-0009zU-P9; Sat, 12 Oct 2019 18:51:57 +0000 Received: from localhost ([127.0.0.1]:24005 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.92.1 (FreeBSD)) (envelope-from ) id 1iJMUf-0009OI-KA; Sat, 12 Oct 2019 18:51:57 +0000 From: Andrew Gierth To: Matthias Apitz Cc: pgsql-general@lists.postgresql.org Subject: Re: SELECT d02name::bytea FROM ... && DBI::Pg In-Reply-To: <20191010112458.GA271079@sh4-5.1blu.de> (Matthias Apitz's message of "Thu, 10 Oct 2019 13:24:58 +0200") Message-ID: <87zhi5vm0z.fsf@news-spur.riddles.org.uk> References: <20191010112458.GA271079@sh4-5.1blu.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (berkeley-unix) Date: Sat, 12 Oct 2019 19:51:57 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Matthias" == Matthias Apitz writes: Matthias> Hello, Matthias> I can SELECT && print a column in hex with: Matthias> pos71=# select d02name::bytea from d02ben where d02bnr = '00001048313' ; If your intention is to see the raw bytes of the stored text value, for example to check the encoding, then you should not do it that way. Casting from text to bytea does NOT do what you think. Instead use convert_to(d02name,'SQL_ASCII') (yes, always specify SQL_ASCII regardless of what encoding you think it should be in, since the actual meaning of SQL_ASCII is "no conversions"). For readability, you may then want to wrap that as encode(convert_to(d02name,'SQL_ASCII'),'escape') which will keep the ASCII characters but use \nnn escapes for non-ascii. -- Andrew (irc:RhodiumToad)