Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-05-11 Thread Jim Nasby
On 4/29/16 8:56 AM, Shulgin, Oleksandr wrote: It would probably make sense model this function after Python's "dump-to-JSON-string" function: https://docs.python.org/2/library/json.html#json.dumps With the optional parameters for sorting the keys, indentation size and punctuation. This way all

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-05-02 Thread Oleksandr Shulgin
On Mon, May 2, 2016 at 4:04 PM, Andrew Dunstan wrote: > > On 05/02/2016 04:56 AM, Shulgin, Oleksandr wrote: > >> On Sun, May 1, 2016 at 3:22 AM, Andrew Dunstan > > wrote: >> >> On 04/29/2016 06:11 PM, Merlin Moncure

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-05-02 Thread Andrew Dunstan
On 05/02/2016 04:56 AM, Shulgin, Oleksandr wrote: On Sun, May 1, 2016 at 3:22 AM, Andrew Dunstan > wrote: On 04/29/2016 06:11 PM, Merlin Moncure wrote: This is a simple matter of removing spaces in the occasional C string

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-05-02 Thread Shulgin, Oleksandr
On Sun, May 1, 2016 at 3:22 AM, Andrew Dunstan wrote: > > On 04/29/2016 06:11 PM, Merlin Moncure wrote: > > This is a simple matter of removing spaces in the occasional C string >> literal in the serialization routines and adding a json_pretty >> function. >> > > I spent a

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-30 Thread Andrew Dunstan
On 04/29/2016 06:11 PM, Merlin Moncure wrote: This is a simple matter of removing spaces in the occasional C string literal in the serialization routines and adding a json_pretty function. I spent a few hours on this. See

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-29 Thread Merlin Moncure
On Fri, Apr 29, 2016 at 4:06 PM, Andrew Dunstan wrote: > One other point: I think we really need most of these pieces - if we are > going to squash the whitespace we need functions to do that cleanly for json > and to pretty-print json. I don't think it should be squashed

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-29 Thread Andrew Dunstan
On 04/29/2016 02:34 PM, Merlin Moncure wrote: I wouldn't necessarily be opposed to us having one or more of the following: a) suppressing whitespace addition in all json generation and text output, possibly governed by a GUC setting so we could maintain behaviour compatibility if required

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-29 Thread Merlin Moncure
On Fri, Apr 29, 2016 at 12:31 PM, Alvaro Herrera wrote: > Thanks Alex for finding the previous thread. > > Andrew Dunstan wrote: >> >> On 04/28/2016 04:29 PM, Alvaro Herrera wrote: > >> >Actually we did have someone come up with a patch to "normalize" how >> >JSON stuff

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-29 Thread Alvaro Herrera
Thanks Alex for finding the previous thread. Andrew Dunstan wrote: > > On 04/28/2016 04:29 PM, Alvaro Herrera wrote: > >Actually we did have someone come up with a patch to "normalize" how > >JSON stuff was output, because our code seems to do it in three > >different, inconsistent ways. And

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-29 Thread David G. Johnston
On Fri, Apr 29, 2016 at 7:15 AM, Merlin Moncure wrote: > Andrew mentions several solutions. I like them all except I would > prefer not to introduce a GUC for controlling the output format. I do > not think it's a good idea to set the expectation that clients can > rely on

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-29 Thread Merlin Moncure
On Wed, Apr 27, 2016 at 4:05 PM, Stephen Frost wrote: > * Merlin Moncure (mmonc...@gmail.com) wrote: >> On Tue, Apr 26, 2016 at 11:49 AM, Stephen Frost wrote: >> > As I mentioned to Sehrope on IRC, at least for my 2c, if you want a >> > compact JSON format

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-29 Thread Shulgin, Oleksandr
On Fri, Apr 29, 2016 at 3:18 PM, Andrew Dunstan wrote: > > On 04/28/2016 04:29 PM, Alvaro Herrera wrote: > >> >>> Actually we did have someone come up with a patch to "normalize" how >> JSON stuff was output, because our code seems to do it in three >> different,

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-29 Thread Andrew Dunstan
On 04/28/2016 04:29 PM, Alvaro Herrera wrote: David G. Johnston wrote: On Thu, Apr 28, 2016 at 10:00 AM, Ryan Pedela wrote: In addition, every JSON implementation I have ever seen fully minimizes JSON by default. PG appears to deviate from standard practice for no

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-28 Thread Sehrope Sarkuni
On Wed, Apr 27, 2016 at 7:09 PM, David G. Johnston < david.g.johns...@gmail.com> wrote: > On Sun, Apr 24, 2016 at 3:02 PM, Sehrope Sarkuni > wrote: > >> Attached is a *very* work in progress patch that adds a >> jsonb_compact(jsonb)::text function. It generates a text

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-28 Thread Alvaro Herrera
David G. Johnston wrote: > On Thu, Apr 28, 2016 at 10:00 AM, Ryan Pedela > wrote: > > In addition, every JSON implementation I have ever seen fully minimizes > > JSON by default. PG appears to deviate from standard practice for no > > apparent reason. > > Sorry to

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-28 Thread David Fetter
On Wed, Apr 27, 2016 at 05:05:18PM -0400, Stephen Frost wrote: > * Merlin Moncure (mmonc...@gmail.com) wrote: > > On Tue, Apr 26, 2016 at 11:49 AM, Stephen Frost wrote: > > > As I mentioned to Sehrope on IRC, at least for my 2c, if you want a > > > compact JSON format to

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-28 Thread David G. Johnston
On Thu, Apr 28, 2016 at 10:00 AM, Ryan Pedela wrote: > On Tue, Apr 26, 2016 at 10:49 AM, Stephen Frost > wrote: > >> * Ryan Pedela (rped...@datalanche.com) wrote: >> > On Sun, Apr 24, 2016 at 4:02 PM, Sehrope Sarkuni >> wrote: >>

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-28 Thread Ryan Pedela
On Tue, Apr 26, 2016 at 10:49 AM, Stephen Frost wrote: > * Ryan Pedela (rped...@datalanche.com) wrote: > > On Sun, Apr 24, 2016 at 4:02 PM, Sehrope Sarkuni > wrote: > > > The default text representation of jsonb adds whitespace in between > > > key/value

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-27 Thread David G. Johnston
On Sun, Apr 24, 2016 at 3:02 PM, Sehrope Sarkuni wrote: > Attached is a *very* work in progress patch that adds a > jsonb_compact(jsonb)::text function. It generates a text representation > without extra whitespace but does not yet try to enforce a stable order of > the

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-27 Thread David G. Johnston
On Sun, Apr 24, 2016 at 3:02 PM, Sehrope Sarkuni wrote: > It'd be nice to have a stable text representation of a jsonb value with > minimal whitespace. The latter would also save a few bytes per record in > text output formats, on the wire, and in backups (ex: COPY ... TO

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-27 Thread Stephen Frost
* Merlin Moncure (mmonc...@gmail.com) wrote: > On Tue, Apr 26, 2016 at 11:49 AM, Stephen Frost wrote: > > As I mentioned to Sehrope on IRC, at least for my 2c, if you want a > > compact JSON format to reduce the amount of traffic over the wire or to > > do things with on the

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-27 Thread Merlin Moncure
On Tue, Apr 26, 2016 at 11:49 AM, Stephen Frost wrote: > * Ryan Pedela (rped...@datalanche.com) wrote: >> On Sun, Apr 24, 2016 at 4:02 PM, Sehrope Sarkuni wrote: >> > The default text representation of jsonb adds whitespace in between >> > key/value pairs

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-27 Thread Dave Cramer
On 26 April 2016 at 12:49, Stephen Frost wrote: > * Ryan Pedela (rped...@datalanche.com) wrote: > > On Sun, Apr 24, 2016 at 4:02 PM, Sehrope Sarkuni > wrote: > > > The default text representation of jsonb adds whitespace in between > > > key/value pairs

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-26 Thread Merlin Moncure
On Sun, Apr 24, 2016 at 8:16 PM, Andrew Dunstan wrote: > Note that the json type, unlike jsonb, preserves exactly the white space and > key order of its input. In fact, the input is exactly what it stores. That is true, but the json serialization functions (to_json etc)

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-26 Thread Stephen Frost
* Ryan Pedela (rped...@datalanche.com) wrote: > On Sun, Apr 24, 2016 at 4:02 PM, Sehrope Sarkuni wrote: > > The default text representation of jsonb adds whitespace in between > > key/value pairs (after the colon ":") and after successive properties > > (after the comma ","):

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-26 Thread Ryan Pedela
On Sun, Apr 24, 2016 at 4:02 PM, Sehrope Sarkuni wrote: > Hi, > > The default text representation of jsonb adds whitespace in between > key/value pairs (after the colon ":") and after successive properties > (after the comma ","): > > postgres=# SELECT

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-25 Thread Sehrope Sarkuni
On Sun, Apr 24, 2016 at 9:27 PM, Stephen Frost wrote: > * Andrew Dunstan (and...@dunslane.net) wrote: > > On 04/24/2016 06:02 PM, Sehrope Sarkuni wrote: > > >AFAIK, there's also no guarantee on the specific order of the > > >resulting properties in the text representation

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-24 Thread Stephen Frost
* Andrew Dunstan (and...@dunslane.net) wrote: > On 04/24/2016 06:02 PM, Sehrope Sarkuni wrote: > >AFAIK, there's also no guarantee on the specific order of the > >resulting properties in the text representation either. I would > >suppose it's fixed for a given jsonb value within a database major >

Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-24 Thread Andrew Dunstan
On 04/24/2016 06:02 PM, Sehrope Sarkuni wrote: AFAIK, there's also no guarantee on the specific order of the resulting properties in the text representation either. I would suppose it's fixed for a given jsonb value within a database major version but across major versions it could change

[HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text

2016-04-24 Thread Sehrope Sarkuni
Hi, The default text representation of jsonb adds whitespace in between key/value pairs (after the colon ":") and after successive properties (after the comma ","): postgres=# SELECT '{"b":2,"a":1}'::jsonb::text; text -- {"a": 1, "b": 2} (1 row) AFAIK, there's also no