Re: BUG #8676: Bug Money JSON

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, email(at)andersonloyola(dot)com(dot)br, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #8676: Bug Money JSON
Date: 2013-12-17 16:16:40
Message-ID: 52B078E8.5020707@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers


On 12/17/2013 10:31 AM, Tom Lane wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>>> On Wed, Dec 11, 2013 at 02:30:04PM +0000, email(at)andersonloyola(dot)com(dot)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.

cheers

andrew

Attachment Content-Type Size
json_money.patch text/x-patch 1.1 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message bneumeier 2013-12-17 17:10:01 BUG #8684: Tables with custom range domain type cannot be analyzed
Previous Message Tom Lane 2013-12-17 15:31:08 Re: BUG #8676: Bug Money JSON

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2013-12-17 16:26:13 Re: SSL: better default ciphersuite
Previous Message Alvaro Herrera 2013-12-17 16:14:32 Re: patch: make_timestamp function