sidorares / sidorares/node-mysql2
Cast of data when retrieving a single value in JSON.
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' FROMjsontableASjsontable;
it fails and return "key2" value as a string : "10"
whereas while using JSON_EXTRACT :
SELECT JSON_EXTRACT(
jsoncol, '$.key2') ASjsoncol.key2FROMjsontableASjsontable;
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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