Re: Abnormal JSON query performance

From: reader 1001 <007reader(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Abnormal JSON query performance
Date: 2018-05-16 03:42:16
Message-ID: CAF0oHxPm=2w7V3-0-stfUt+Yrt7rP_24QZi5w71ysORbu2Se+A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Yes, I realized it by now, thank you.
My question remains for hierarchical keys in a JSON document. If I have a
document like below, I clearly can extract key1 using the described rowtype
definition. How can I specify selected keys deeper in the document, e.g.
key3 and key5?
{
key1:value1,
key2: {
key3:value3},
key4:[
{
key5:value5
},
{
key6:value6
}
]
}

Thank you for your help.

On Tue, May 15, 2018 at 1:42 AM, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
wrote:

> > On 14 May 2018 at 23:37, 007reader <007reader(at)gmail(dot)com> wrote:
> > It would be great to document jsonb_populate_record better, especially
> the
> > rowtype. May be it is obvious to an experienced user, but for a less
> > experienced it isn't clear how it should be defined. Only after Tom's
> email,
> > I realized that it can be done without creating a table.
> >
> > My use case may be a bit more complex:
> > 1. My JSON doc is large - few hundred keys and it is not practical to
> define
> > rowtype for the entire doc. Plus not all docs have all keys in each
> record.
> > I'd like to specify only a relatively small number of keys (by their
> path)
> > for jsonb_populate_record instead of the entire json field.
> > 2. My docs have hierarchical structure, but the output should be
> flattened
> > base on the structure defined in #1.
> >
> > Can those problems be addressed within the current implementation?
>
> Just to mention about #1. If I understand you correctly, it's not
> necessary to
> define a rowtype for the entire doc, you can do this only for a part
> that you want to extract from the document. It's also fine to have
> some keys missing:
>
> create type test as (a integer, b text, c text);
> select * from json_populate_record(null::test, '{"a": 1, "b":
> "test", "d": "test2"}');
>
> a | b | c
> ---+------+------
> 1 | test | NULL
> (1 row)
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2018-05-16 03:59:25 Re: Abnormal JSON query performance
Previous Message Euler Taveira 2018-05-15 21:26:32 Re: ERROR: subxact logged without previous toplevel record