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

sql: support missing JSON numeric scalar casts #41333

Closed
jordanlewis opened this issue Oct 4, 2019 · 3 comments · Fixed by #41367
Closed

sql: support missing JSON numeric scalar casts #41333

jordanlewis opened this issue Oct 4, 2019 · 3 comments · Fixed by #41367
Assignees
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) good first issue

Comments

@jordanlewis
Copy link
Member

It should be possible to cast JSON scalars to their corresponding SQL types, but it currently is not possible.

We should support:

JSON numeric -> int
JSON numeric -> float
JSON numeric -> decimal
JSON numeric -> string

This change should be pretty straightforward - CastExpr.Eval should be edited in eval.go to add the missing cases, and tests added to pkg/sql/sem/tree/testdata/eval/cast.

@jordanlewis jordanlewis added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) good first issue labels Oct 4, 2019
@97amarnathk
Copy link

I would like to work on this.

@jordanlewis
Copy link
Member Author

@97amarnathk I think @chrisseto has an ongoing patch for this. I'll assign him to prevent confusion.

@97amarnathk
Copy link

Okay.

@chrisseto chrisseto self-assigned this Oct 6, 2019
chrisseto added a commit to chrisseto/cockroach that referenced this issue Oct 6, 2019
* Fixes cockroachdb#41333
* Add support for queries such as
  - `SELECT '1'::jsonb::int`
  - `SELECT '1'::jsonb::float`
  - `SELECT '3.14'::jsonb::decimal`

Release note: None
craig bot pushed a commit that referenced this issue Feb 12, 2021
41367: sql: Add support for numeric JSON scalar casts r=rafiss a=chrisseto

* Fixes #41333
* Add support for queries such as
  - `SELECT '1'::jsonb::int`
  - `SELECT '1'::jsonb::float`
  - `SELECT '3.14'::jsonb::decimal`

Release note (sql change): Casting JSON numeric scalars to numeric
types now works as expected.

Co-authored-by: Chris Seto <chriskseto@gmail.com>
@craig craig bot closed this as completed in 6c64c60 Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants