Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ai70D-0001V5-6q for pgsql-bugs@arkaria.postgresql.org; Mon, 21 Mar 2016 21:04:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ai70C-0005AK-LV for pgsql-bugs@arkaria.postgresql.org; Mon, 21 Mar 2016 21:04:40 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ai70C-0005A0-1x for pgsql-bugs@postgresql.org; Mon, 21 Mar 2016 21:04:40 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ai709-0006qR-5g for pgsql-bugs@postgresql.org; Mon, 21 Mar 2016 21:04:38 +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 u2LL4aKl001164; Mon, 21 Mar 2016 17:04:36 -0400 From: Tom Lane To: Reece Pegues cc: "pgsql-bugs@postgresql.org" Subject: Re: BUG #14038: substring cuts unicode char in half, allowing to save broken utf8 into table In-reply-to: References: <20160321143927.2903.55302@wrigleys.postgresql.org> <22852.1458578790@sss.pgh.pa.us> Comments: In-reply-to Reece Pegues message dated "Mon, 21 Mar 2016 17:10:45 -0000" Date: Mon, 21 Mar 2016 17:04:36 -0400 Message-ID: <1163.1458594276@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Reece Pegues writes: > Looks like the database is created with ENCODING = 'SQL_ASCII' Basically what that does is defeats all encoding checks inside the backend; it'll store whatever bytes you give it. So yeah, substring() is expected to deal in bytes not characters in this encoding. > So I assume it was thus saving the data that way, and then if the client > encoding is utf8 it tried to encode to that and failed? If client declares its encoding, the backend will verify correct encoding before transmitting data; but if the database encoding is SQL_ASCII then no actual conversion happens, only a validity check at transmit/receive. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs