Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for standard JSON functions - continued #8950

Closed
20 tasks done
lukaseder opened this issue Jul 16, 2019 · 5 comments
Closed
20 tasks done

Add support for standard JSON functions - continued #8950

lukaseder opened this issue Jul 16, 2019 · 5 comments

Comments

@lukaseder
Copy link
Member

lukaseder commented Jul 16, 2019

This is a continuation of #8944 from jOOQ 3.12

With JSON data type support having been added to jOOQ 3.12 (see #7242), it would be useful to also support standard SQL JSON functions, such as:

There are also some interesting vendor specific functions, such as:

Most of this will be out of scope for jOOQ 3.12 and moved to 3.14

@lukaseder lukaseder added this to the Version 3.13.0 milestone Jul 16, 2019
lukaseder added a commit that referenced this issue Mar 11, 2020
lukaseder added a commit that referenced this issue Mar 11, 2020
lukaseder added a commit that referenced this issue Mar 27, 2020
lukaseder added a commit that referenced this issue Mar 27, 2020
lukaseder added a commit that referenced this issue Mar 27, 2020
lukaseder added a commit that referenced this issue Apr 16, 2020
lukaseder added a commit that referenced this issue Apr 16, 2020
@lukaseder
Copy link
Member Author

Almost finished. Only documentation is still missing...

@lukaseder
Copy link
Member Author

The PostgreSQL JSON_TABLE .. FOR ORDINALITY clause is currently being emulated using ROW_NUMBER() OVER (), but that risks not being 100% reliable as there is no guarantee that the jsonb_path_query() produces a table whose ordering is maintained until ROW_NUMBER() OVER () is calculated.

Luckily, PostgreSQL supports WITH ORDINALITY on all table valued functions, so we can write this:

select *
from jsonb_path_query('["a","b","c"]', '$[*]') with ordinality;

Producing:

jsonb_path_query|ordinality|
----------------|----------|
"a"             |         1|
"b"             |         2|
"c"             |         3|

@mkurz
Copy link

mkurz commented Nov 22, 2020

Hey @lukaseder,

reading the docs about JSON_TABLE:

First:
In the jOOQ example on the right side the double quotes are missing:

JSON.valueOf("[{\"a\":5,\"b\":{\"x\":10}},
// should be:
JSON.valueOf("[{\"a\":5,\"b\":{\"x\":10}},"

Second:
When executing this example with Postgres 13 I get following error (taken right from the logs with config log_statement = 'all'):

2020-11-22 15:45:52.029 UTC [12377] ERROR:  subquery in FROM must have an alias at character 33
2020-11-22 15:45:52.029 UTC [12377] HINT:  For example, FROM (SELECT ...) [AS] foo.
2020-11-22 15:45:52.029 UTC [12377] STATEMENT:  select "id", "a", "x", "y" from (select o as "id", (jsonb_path_query_first(j, '$.a'::jsonpath)->>0)::int as "a", (jsonb_path_query_first(j, $1::jsonpath)->>0)::int as "x", (jsonb_path_query_first(j, $2::jsonpath)->>0)::int as "y" from jsonb_path_query(cast($3 as jsonb), $4::jsonpath) with ordinality as t(j, o))

BTW: I see you are emulating the missing JSON_TABLE function by using jsonb_path_query/_first. I guess you are following
https://commitfest.postgresql.org/28/1473/ already? 😉

@lukaseder
Copy link
Member Author

In the jOOQ example on the right side the double quotes are missing:

Thanks! Fixed.

Second:

Can you please create a new issue with steps to reproduce this?

@mkurz
Copy link

mkurz commented Nov 23, 2020

Can you please create a new issue with steps to reproduce this?

#11014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants