Re: [HACKERS] SQL/JSON in PostgreSQL
От | Nikita Glukhov |
---|---|
Тема | Re: [HACKERS] SQL/JSON in PostgreSQL |
Дата | |
Msg-id | a7ebb5d0-2bb2-6ff1-8d92-5dcaf35d3d94@postgrespro.ru обсуждение исходный текст |
Ответ на | Re: [HACKERS] SQL/JSON in PostgreSQL (Pavel Stehule <pavel.stehule@gmail.com>) |
Список | pgsql-hackers |
On 07.01.2018 00:33, Pavel Stehule wrote:
This is non-standard feature, but it can be easily added for compatibility with other implementations.2018-01-06 22:23 GMT+01:00 Nikita Glukhov <n.gluhov@postgrespro.ru>:".title" simply should go after the filter:On 07.01.2018 00:22, Pavel Stehule wrote:
-- not sure, if it is correctHow I can get title of book with cost 6?I am not jsonpath expert, so I can be badHiI try jsonpath on json
{
"book":
[
{
"title": "Beginning JSON",
"author": "Ben Smith",
"price": 49.99
},
{
"title": "JSON at Work",
"author": "Tom Marrs",
"price": 29.99
},
{
"title": "Learn JSON in a DAY",
"author": "Acodemy",
"price": 8.99
},
{
"title": "JSON: Questions and Answers",
"author": "George Duckett",
"price": 6.00
}
],
"price range":
{
"cheap": 10.00,
"medium": 20.00
}
}
postgres=# select j @* '$.book[*] ? (@.price==6)' from test;
┌─────────────────────────────────────────────────────┐
│ ?column? │
╞═════════════════════════════════════════════════════╡
│ {↵│
│ "title": "JSON: Questions and Answers",↵│
│ "author": "George Duckett", ↵│
│ "price": 6.00 ↵│
│ }↵│
││
└─────────────────────────────────────────────────────┘
(1 row)postgres=# select j @* '$.book[*].title ? (@.price==6)' from test;
┌──────────┐
│ ?column? │
╞══════════╡
└──────────┘
(0 rows)I found some examples, where the filter has bigger sense, but it is not supportedLINE 1: select j @* '$.book[?(@.price==6.00)].title' from test;
^
DETAIL: syntax error, unexpected '?' at or near "?"
select j @* '$.book[*] ? (@.price==6.00).title' from test;It is working, thank you.and the form "$.book[?(@.price==6.00)].title" ? I found this example in some other SQL/JSON implementations.
В списке pgsql-hackers по дате отправления: