Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vwfot-0004vF-A2 for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Dec 2013 22:23:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vwfos-0000Nz-QK for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Dec 2013 22:23:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vwfor-0000Nq-RC; Fri, 27 Dec 2013 22:23:49 +0000 Received: from relay5-d.mail.gandi.net ([2001:4b98:c:538::197]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vwfop-0006GX-An; Fri, 27 Dec 2013 22:23:49 +0000 Received: from mfilter4-d.gandi.net (mfilter4-d.gandi.net [217.70.178.134]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 16EEE41C051; Fri, 27 Dec 2013 23:23:44 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter4-d.gandi.net Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by mfilter4-d.gandi.net (mfilter4-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id mxsmlTOVRaNn; Fri, 27 Dec 2013 23:23:43 +0100 (CET) X-Originating-IP: 98.27.58.255 Received: from [192.168.10.146] (cpe-098-027-058-255.nc.res.rr.com [98.27.58.255]) (Authenticated sender: adsend@dunslane.net) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id AE6D241C060; Fri, 27 Dec 2013 23:23:40 +0100 (CET) Message-ID: <52BDFDEA.3000304@dunslane.net> Date: Fri, 27 Dec 2013 17:23:38 -0500 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Tom Lane CC: Bruce Momjian , email@andersonloyola.com.br, pgsql-bugs@postgresql.org, PostgreSQL-development Subject: Re: BUG #8676: Bug Money JSON References: <20131217141021.GA19059@momjian.us> <52B06330.1010503@dunslane.net> <10585.1387294268@sss.pgh.pa.us> <52B078E8.5020707@dunslane.net> <52BC72A6.2040808@dunslane.net> In-Reply-To: <52BC72A6.2040808@dunslane.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 On 12/26/2013 01:17 PM, Andrew Dunstan wrote: > > On 12/17/2013 11:16 AM, Andrew Dunstan wrote: >> >> On 12/17/2013 10:31 AM, Tom Lane wrote: >>> Andrew Dunstan writes: >>>>> On Wed, Dec 11, 2013 at 02:30:04PM +0000, >>>>> email@andersonloyola.com.br wrote: >>>>>> postgres=# SELECT to_json(a) FROM (VALUES(1000::money)) a(salario); >>>>>> to_json >>>>>> ----------------------- >>>>>> {"salario":$1,000.00} >>>>>> (1 row) >>>> Yeah. I'll have a look. In fact this looks like it's possibly a couple >>>> of bugs. The JSON produced by the first query is not valid. It looks >>>> like we might need to force money to text unconditionally. >>> Isn't this simply failure to quote the string properly? What drives >>> to_json's choice of whether to quote or not, anyway? >>> >>> >> >> >> If it's numeric, it only quotes if it sees a non-numeric character, >> defined thus: >> >> /* letters appearing in numeric output that aren't valid in a JSON >> number */ >> #define NON_NUMERIC_LETTER "NnAaIiFfTtYy" >> >> >> I forgot about money when I did that - some of this dates back to 9.2. >> >> I'm about to test the attached patch which should force money to be >> quoted always. >> >> > > > This turned out to be not such a good idea. Quite apart from anything > else it doesn't handle domains over money at all well. > > The attached patch abandons the test described above, and instead > passes the string from the output function to the json number lexer to > see if it's a valid json number. A small adjustment to the API of > that function was required to make it suitable for this use. This > seems like a much more robust approach. > > Applied. cheers andrew -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs