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

Db2 cannot handle scalar subqueries in JSON_OBJECT in the presence of a MULTISET ad-hoc converter #12189

Closed
lukaseder opened this issue Jul 14, 2021 · 5 comments

Comments

@lukaseder
Copy link
Member

This doesn't work in Db2:

select 
  json_object(
    key 'v0' value 4,
    key 'v1' value (
      select 'a'
      from SYSIBM.DUAL
    )
  )
from SYSIBM.DUAL;

The above produces:

SQL Error [42601]: An unexpected token ")" was found following "SYSIBM.DUAL ) ". Expected tokens may include: "<interval_qualifier>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.28.11

Casting the value to a VARCHAR "fixes" it

select 
  json_object(
    key 'v0' value 4,
    key 'v1' value cast((
      select 'a'
      from SYSIBM.DUAL
    ) as varchar(32672))
  )
from SYSIBM.DUAL;
@lukaseder
Copy link
Member Author

I seem to have already fixed this, but the fix didn't work in this case:
https://stackoverflow.com/a/64350132/521799

@lukaseder
Copy link
Member Author

The fix doesn't work when there's an ad-hoc converter!

@lukaseder lukaseder changed the title Db2 cannot handle scalar subqueries in JSON_OBJECT Db2 cannot handle scalar subqueries in JSON_OBJECT in the presence of a MULTISET ad-hoc converter Jul 14, 2021
@lukaseder
Copy link
Member Author

The problem is that we do an field instanceof ScalarSubquery check, rather than calling Tools.uncoerce(field), first. It's probably always wrong to just check for something being an instanceof ScalarSubquery

@lukaseder
Copy link
Member Author

There we go.

image

@lukaseder
Copy link
Member Author

Fixed in jOOQ 3.16.0 and 3.15.1 (#12190)

lukaseder added a commit that referenced this issue Jul 14, 2021
lukaseder added a commit that referenced this issue Jul 14, 2021
@lukaseder lukaseder changed the title Db2 cannot handle scalar subqueries in JSON_OBJECT in the presence of a MULTISET ad-hoc converter Db2 cannot handle scalar subqueries originating from MULTISET in JSON_OBJECT in the presence of a MULTISET ad-hoc converter Jun 15, 2022
@lukaseder lukaseder changed the title Db2 cannot handle scalar subqueries originating from MULTISET in JSON_OBJECT in the presence of a MULTISET ad-hoc converter Db2 cannot handle scalar subqueries in JSON_OBJECT in the presence of a MULTISET ad-hoc converter Jun 15, 2022
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

1 participant