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 1iZHDJ-0002pX-2r for pgsql-general@arkaria.postgresql.org; Mon, 25 Nov 2019 16:27:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iZHDH-0004Nu-RU for pgsql-general@arkaria.postgresql.org; Mon, 25 Nov 2019 16:27:47 +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 1iZHDH-0004Nl-HV for pgsql-general@lists.postgresql.org; Mon, 25 Nov 2019 16:27:47 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iZHDE-0003RF-Ci for pgsql-general@lists.postgresql.org; Mon, 25 Nov 2019 16:27:47 +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 xAPGReox003580; Mon, 25 Nov 2019 11:27:40 -0500 From: Tom Lane To: Bob Jolliffe cc: pgsql-general@lists.postgresql.org Subject: Re: casting Bangla characters to NUMERIC In-reply-to: References: Comments: In-reply-to Bob Jolliffe message dated "Mon, 25 Nov 2019 16:02:32 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3578.1574699260.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 25 Nov 2019 11:27:40 -0500 Message-ID: <3579.1574699260@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Bob Jolliffe writes: > I have an interesting problem. I have a string field in a table which > (sometimes) is expected to contain numeric values ie. a cast of the > field to INTEGER is supposed to succeed. > My issue is that the application is running in Bangladesh, and > sometimes the users have entered values using Bangla characters. eg. > "৮" rather than "8". (Note that this shouldnt have been possible to > enter in the first place, but we can ignore that for now. They are > there, I have to somehow deal with it.) > Is there a way with LOCALE settings to get this cast to work > correctly? Doubt it :-(. ISTM it's certainly outside the charter of int4in to do that. Ideally to_number() would handle it, but I don't think it does at the moment. Probably your best bet is to translate those characters to regular ASCII digits using replace(), then cast. It'd be a bit tedious, but fortunately there are only 10 cases to consider, and you could wrap that up in a function. regards, tom lane