Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 742B06329DF for ; Tue, 3 Nov 2009 22:29:52 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 50780-03 for ; Wed, 4 Nov 2009 02:29:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id AC35A63222F for ; Tue, 3 Nov 2009 22:29:41 -0400 (AST) Received: from [10.0.0.53] (wallace.localnet [10.0.0.53]) by mail.postnewspapers.com.au (Postfix) with ESMTP id A81E11E0440; Wed, 4 Nov 2009 10:29:35 +0800 (WST) Message-ID: <4AF0E70F.1030201@postnewspapers.com.au> Date: Wed, 04 Nov 2009 10:29:35 +0800 From: Craig Ringer User-Agent: Thunderbird 2.0.0.21 (X11/20090409) MIME-Version: 1.0 To: Bryce Nesbitt CC: pgsql-sql@postgresql.org Subject: Re: Why don't I get a LATIN1 encoding here with SET ENCODING? References: <4AF0D531.5080309@obviously.com> In-Reply-To: <4AF0D531.5080309@obviously.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.279 tagged_above=-10 required=5 tests=AWL=0.320, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/5 X-Sequence-Number: 33356 Bryce Nesbitt wrote: > I'm tracking another bug, but wanted to verify stuff on the command line. I > can't figure out why this did not work: > dblack3-deleteme=> insert into bryce1 values(1,2,'test\375'); > ERROR: invalid byte sequence for encoding "UTF8": 0xfd I'd say the server is interpreting your query text as latin-1 and converting it to the server encoding UTF-8 as it should, resulting in the utf-8 string: insert into bryce1 values(1,2,'test\375'); which it *then* interprets escapes in. As test\xfd ('0x74 0x65 0x73 0x74 0xfd') isn't valid UTF-8, the server rejects it. If my understanding is right then the trouble is that the client_encoding setting doesn't affect string escapes in SQL queries. The conversion of the query text from client to server encoding is done before string escapes are processed. In truth, that's how I'd expect it to happen. If I ask for the byte 0xfd in a string, I don't want the server to decide that I must've meant something else because I have a different client encoding. If I wanted encoding conversion, I wouldn't have written it in an escape form, I'd have written 'ý' not '\375'. -- Craig Ringer