sidorares / sidorares/node-mysql2

Cast of data when retrieving a single value in JSON.

Open
#953 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

Hi,

I'm fairly new to the using of JSON columns/this library, and I have some questions.

My data are stored like that in my 'jsoncol':

{
"key1": "value1", 
"key2": 10
}

If I query the json col directly (select jsoncol from jsontable;) it gets the entire object with the good type no problem.

But what if I want to retrieve only "key2", while using the "simple" MySQL syntaxe :

SELECT jsoncol->>'$.key2' FROM jsontable AS jsontable;

it fails and return "key2" value as a string : "10"

whereas while using JSON_EXTRACT :

SELECT JSON_EXTRACT(jsoncol, '$.key2') AS jsoncol.key2 FROM jsontable AS jsontable;

it is returned as a number.

My question is : is this normal? Do I have to use JSON_EXTRACT to get a single key with the good type? I'm using the query method, is it better to use execute?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the two JSON queries described in the issue through the query and execute methods, then compare the returned value and type. The issue names no source files or tests; done would mean determining whether the differing cast is expected and identifying the relevant behavior or documentation to update.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, node.js, typescript
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.