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 1iwDS4-000605-I1 for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Jan 2020 23:05:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iwDS3-0007iC-BE for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Jan 2020 23:05:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iwDS3-0007i5-03 for pgsql-bugs@lists.postgresql.org; Mon, 27 Jan 2020 23:05:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iwDS0-00025t-C6 for pgsql-bugs@lists.postgresql.org; Mon, 27 Jan 2020 23:05:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 00RN5jnv025296; Mon, 27 Jan 2020 18:05:45 -0500 From: Tom Lane To: stephane.campinas@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16236: Invalid escape encoding In-reply-to: <16236-887912799bb3eb3c@postgresql.org> References: <16236-887912799bb3eb3c@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 27 Jan 2020 22:21:55 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25294.1580166345.1@sss.pgh.pa.us> Date: Mon, 27 Jan 2020 18:05:45 -0500 Message-ID: <25295.1580166345@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > From the documentation [0] about the encode function, the "escape" format > should "convert zero bytes and high-bit-set bytes to octal sequences (\nnn) > and doubles backslashes." > However, executing "select encode(E'aaa\bccc', 'escape');" outputs > "aaa\x08ccc", although according to the documentation I should get > "aaa\010ccc". No, I don't think so. The \b gives rise to a byte with hex value 08 (that is, control-H or backspace) in the E'' literal, which converts to the same byte value in the bytea value that gets passed to encode(). Since that's not either a zero or a high-bit-set value, encode() just repeats it literally in the text result, and you end up with the same thing as if you'd just done =# select E'aaa\bccc'::text; text ------------ aaa\x08ccc (1 row) I think it must be psql itself that's choosing to represent the backspace as \x08, because nothing in the backend does that. (pokes around ... yeah, it's pg_wcsformat() that's doing it) You could certainly make an argument that encode() ought to backslashify all ASCII control characters, not only \0. But it's behaving as documented, AFAICS. regards, tom lane