pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Dunstan <andrew@dunslane.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Bruce Momjian <bruce@momjian.us>
Cc: email@andersonloyola.com.br
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8676: Bug Money JSON
Date: Tue, 17 Dec 2013 11:16:40 -0500
Message-ID: <52B078E8.5020707@dunslane.net> (raw)
In-Reply-To: <10585.1387294268@sss.pgh.pa.us>
References: <E1Vqknc-0007nO-5S@wrigleys.postgresql.org>
	<20131217141021.GA19059@momjian.us>
	<52B06330.1010503@dunslane.net>
	<10585.1387294268@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>


On 12/17/2013 10:31 AM, Tom Lane wrote:
> Andrew Dunstan <andrew@dunslane.net> 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.

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

Attachments:

json_money.patch (text/x-patch, 1.1K) download diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c index d8ebf4e..f1c7195 100644 --- a/src/backend/utils/adt/json.c +++ b/src/backend/utils/adt/json.c @@ -1381,6 +1381,8 @@ array_to_json_internal(Datum array, StringInfo result, bool use_line_feeds) tcategory = TYPCATEGORY_COMPOSITE; else if (element_type == JSONOID) tcategory = TYPCATEGORY_JSON; + else if (element_type == CASHOID) + tcategory = TYPCATEGORY_STRING; else tcategory = TypeCategory(element_type); @@ -1476,6 +1478,8 @@ composite_to_json(Datum composite, StringInfo result, bool use_line_feeds) tcategory = TYPCATEGORY_COMPOSITE; else if (tupdesc->attrs[i]->atttypid == JSONOID) tcategory = TYPCATEGORY_JSON; + else if (tupdesc->attrs[i]->atttypid == CASHOID) + tcategory = TYPCATEGORY_STRING; else tcategory = TypeCategory(tupdesc->attrs[i]->atttypid); @@ -1602,6 +1606,8 @@ to_json(PG_FUNCTION_ARGS) tcategory = TYPCATEGORY_COMPOSITE; else if (val_type == JSONOID) tcategory = TYPCATEGORY_JSON; + else if (val_type == CASHOID) + tcategory = TYPCATEGORY_STRING; else tcategory = TypeCategory(val_type);

view thread (7+ messages)  latest in thread

Message-ID: <52B078E8.5020707@dunslane.net>
Permalink:  ../52B078E8.5020707@dunslane.net/
Also on:    postgresql.org/message-id/52B078E8.5020707@dunslane.net

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andrew@dunslane.net, tgl@sss.pgh.pa.us, bruce@momjian.us, email@andersonloyola.com.br
  Subject: Re: BUG #8676: Bug Money JSON
  In-Reply-To: <52B078E8.5020707@dunslane.net>
  References: <E1Vqknc-0007nO-5S@wrigleys.postgresql.org> <20131217141021.GA19059@momjian.us> <52B06330.1010503@dunslane.net> <10585.1387294268@sss.pgh.pa.us> <52B078E8.5020707@dunslane.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox