DEFAULT json_string ON EMPTY: the provided json_string is parsed as JSON, as
long as it is valid, and stored instead of the missing value. Column type
rules also apply to the default value.
I am not sure why MySQL chose to do this. Looking into the SQL Standard, one
can see:
<JSON table regular column definition> ::=
<column name> <data type>
[ PATH <JSON table column path specification> ]
[ <JSON table column empty behavior> ON EMPTY ]
[ <JSON table column error behavior> ON ERROR ]
<JSON table column empty behavior> ::=
ERROR
| NULL
| DEFAULT <value expression>
This doesn't say whether the <value expression> should be interepreted as JSON
or just as a value. But one can find this passage:
Without Feature T826, "General value expression in ON ERROR or ON EMPTY
clauses", the <value
expression> contained in <JSON table column empty behavior> or <JSON table
column error behavior>
contained in a <JSON table regular column definition> JTRCD shall be a
<literal> that can be cast to the
data type specified by the <data type> contained in JTRCD without raising an
exception condition
according to the General Rules of Subclause 6.13, "<cast specification>".
The important part is:
... shall be a <literal> that can be cast to the data type specified ...
which means it is not JSON. It is just a literal, and literal can be a string
literal (in quotes, 'string') or an integer literal (without quotes) or other
kind of literal.
MDEV-25822 JSON_TABLE: default values should allow non-string literals
(Polished initial patch by Alexey Botchkov)
Make the code handle DEFAULT values of any datatype
- Make Json_table_column::On_response::m_default be Item*, not LEX_STRING.
- Change the parser to use string literal non-terminals for producing
the DEFAULT value
-- Also, stop updating json_table->m_text_literal_cs for the DEFAULT
value literals as it is not used.
Need to check which version to push this into
Sergei Petrunia
added a comment - - edited Merged:
commit eaff5ae82168825f036dff00b5c9cc16a004c4ac (HEAD -> bb-10.6-MDEV-25822, origin/bb-10.6-MDEV-25822)
Author: Sergei Petrunia <sergey@mariadb.com>
Date: Tue Jul 23 14:33:33 2024 +0300
MDEV-25822 JSON_TABLE: default values should allow non-string literals
(Polished initial patch by Alexey Botchkov)
Make the code handle DEFAULT values of any datatype
- Make Json_table_column::On_response::m_default be Item*, not LEX_STRING.
- Change the parser to use string literal non-terminals for producing
the DEFAULT value
-- Also, stop updating json_table->m_text_literal_cs for the DEFAULT
value literals as it is not used.
Need to check which version to push this into
MDEV-25822 JSON_TABLE: default values should allow non-string literals
(Polished initial patch by Alexey Botchkov)
added a few more commits and passed to holyfoot to look at. Now the ball is on Alexey's turf.
Now changed issue status to reflect this too.
Sergei Petrunia
added a comment - - edited Ok maybe it wasn't explicitly specified but a month ago I took Alexey's patch, reviewed it, applied my own input and committed as
commit eaff5ae82168825f036dff00b5c9cc16a004c4ac (HEAD -> bb-10.6-MDEV-25822, origin/bb-10.6-MDEV-25822)
Author: Sergei Petrunia <sergey@mariadb.com>
Date: Tue Jul 23 14:33:33 2024 +0300
MDEV-25822 JSON_TABLE: default values should allow non-string literals
(Polished initial patch by Alexey Botchkov)
added a few more commits and passed to holyfoot to look at. Now the ball is on Alexey's turf.
Now changed issue status to reflect this too.
'$' columns(col1 INT path '$.a'default 1 on empty)) as T;
select *
from
json_table('{"a": "123"}',
'$' columns(col1 date path '$.date'defaultdate'2020-01-01'on empty)) as T;
Sergei Petrunia
added a comment - - edited Notes for the documentation (needs editing):
JSON_TABLE allows to specify default column values (See https://mariadb.com/kb/en/json_table/ )
Before this patch, one had to specify default values as string constants.
After this patch, one can specify default values as any literals (string, integer, decimal number, date literal, etc)
NOTE: https://mariadb.com/kb/en/json_table/ needs to be updated to reflect this change!
select *
from
json_table( '{"a": "123"}' ,
'$' columns(col1 INT path '$.a' default 1 on empty)) as T;
select *
from
json_table( '{"a": "123"}' ,
'$' columns(col1 date path '$.date' default date '2020-01-01' on empty)) as T;
People
Sergei Petrunia
Sergei Petrunia
Votes:
0Vote for this issue
Watchers:
4Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":756.1999998092651,"ttfb":175.19999980926514,"pageVisibility":"visible","entityId":100134,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":1,"journeyId":"48c16219-79a2-4be1-9b75-ac88432662c2","navigationType":0,"readyForUser":835.5,"redirectCount":0,"resourceLoadedEnd":877.7999997138977,"resourceLoadedStart":180.59999990463257,"resourceTiming":[{"duration":6.900000095367432,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":180.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":180.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":187.5,"responseStart":0,"secureConnectionStart":0},{"duration":6.900000095367432,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":180.89999961853027,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":180.89999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":187.7999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":68.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":181,"connectEnd":181,"connectStart":181,"domainLookupEnd":181,"domainLookupStart":181,"fetchStart":181,"redirectEnd":0,"redirectStart":0,"requestStart":181,"responseEnd":249.59999990463257,"responseStart":249.59999990463257,"secureConnectionStart":181},{"duration":140.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":181.19999980926514,"connectEnd":181.19999980926514,"connectStart":181.19999980926514,"domainLookupEnd":181.19999980926514,"domainLookupStart":181.19999980926514,"fetchStart":181.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":181.19999980926514,"responseEnd":321.8999996185303,"responseStart":321.8999996185303,"secureConnectionStart":181.19999980926514},{"duration":144.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":181.2999997138977,"connectEnd":181.2999997138977,"connectStart":181.2999997138977,"domainLookupEnd":181.2999997138977,"domainLookupStart":181.2999997138977,"fetchStart":181.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":181.2999997138977,"responseEnd":325.69999980926514,"responseStart":325.69999980926514,"secureConnectionStart":181.2999997138977},{"duration":144.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":181.59999990463257,"connectEnd":181.59999990463257,"connectStart":181.59999990463257,"domainLookupEnd":181.59999990463257,"domainLookupStart":181.59999990463257,"fetchStart":181.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":181.59999990463257,"responseEnd":326.09999990463257,"responseStart":326.09999990463257,"secureConnectionStart":181.59999990463257},{"duration":144.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":181.69999980926514,"connectEnd":181.69999980926514,"connectStart":181.69999980926514,"domainLookupEnd":181.69999980926514,"domainLookupStart":181.69999980926514,"fetchStart":181.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":181.69999980926514,"responseEnd":326.59999990463257,"responseStart":326.59999990463257,"secureConnectionStart":181.69999980926514},{"duration":207.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":181.7999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":181.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":388.8999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":145.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":182,"connectEnd":182,"connectStart":182,"domainLookupEnd":182,"domainLookupStart":182,"fetchStart":182,"redirectEnd":0,"redirectStart":0,"requestStart":182,"responseEnd":327.69999980926514,"responseStart":327.69999980926514,"secureConnectionStart":182},{"duration":206.90000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":182.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":182.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":389.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":146.2000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":182.39999961853027,"connectEnd":182.39999961853027,"connectStart":182.39999961853027,"domainLookupEnd":182.39999961853027,"domainLookupStart":182.39999961853027,"fetchStart":182.39999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":182.39999961853027,"responseEnd":328.59999990463257,"responseStart":328.59999990463257,"secureConnectionStart":182.39999961853027},{"duration":403.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":187.2999997138977,"connectEnd":187.2999997138977,"connectStart":187.2999997138977,"domainLookupEnd":187.2999997138977,"domainLookupStart":187.2999997138977,"fetchStart":187.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":187.2999997138977,"responseEnd":590.8999996185303,"responseStart":590.8999996185303,"secureConnectionStart":187.2999997138977},{"duration":506.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":192.7999997138977,"connectEnd":192.7999997138977,"connectStart":192.7999997138977,"domainLookupEnd":192.7999997138977,"domainLookupStart":192.7999997138977,"fetchStart":192.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":192.7999997138977,"responseEnd":699.5999999046326,"responseStart":699.5999999046326,"secureConnectionStart":192.7999997138977},{"duration":191.2999997138977,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":400,"connectEnd":400,"connectStart":400,"domainLookupEnd":400,"domainLookupStart":400,"fetchStart":400,"redirectEnd":0,"redirectStart":0,"requestStart":400,"responseEnd":591.2999997138977,"responseStart":591.2999997138977,"secureConnectionStart":400},{"duration":51.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":660.2999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":660.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":711.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":211,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":661.1999998092651,"connectEnd":661.1999998092651,"connectStart":661.1999998092651,"domainLookupEnd":661.1999998092651,"domainLookupStart":661.1999998092651,"fetchStart":661.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":661.1999998092651,"responseEnd":872.1999998092651,"responseStart":872.1999998092651,"secureConnectionStart":661.1999998092651},{"duration":216.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":661.5999999046326,"connectEnd":661.5999999046326,"connectStart":661.5999999046326,"domainLookupEnd":661.5999999046326,"domainLookupStart":661.5999999046326,"fetchStart":661.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":661.5999999046326,"responseEnd":877.7999997138977,"responseStart":877.7999997138977,"secureConnectionStart":661.5999999046326},{"duration":225.2999997138977,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":749.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":749.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":974.3999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":200.40000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":769.2999997138977,"connectEnd":769.2999997138977,"connectStart":769.2999997138977,"domainLookupEnd":769.2999997138977,"domainLookupStart":769.2999997138977,"fetchStart":769.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":769.2999997138977,"responseEnd":969.6999998092651,"responseStart":969.6999998092651,"secureConnectionStart":769.2999997138977}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":6,"responseStart":175,"responseEnd":192,"domLoading":178,"domInteractive":902,"domContentLoadedEventStart":902,"domContentLoadedEventEnd":955,"domComplete":1178,"loadEventStart":1178,"loadEventEnd":1178,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":872.6999998092651},{"name":"bigPipe.sidebar-id.end","time":873.3999996185303},{"name":"bigPipe.activity-panel-pipe-id.start","time":873.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":876.3999996185303},{"name":"activityTabFullyLoaded","time":985.8999996185303}],"measures":[],"correlationId":"442f8341d4739b","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":103,"dbReadsTimeInMs":8,"dbConnsTimeInMs":16,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Merged:
commit eaff5ae82168825f036dff00b5c9cc16a004c4ac (HEAD -> bb-10.6-MDEV-25822, origin/bb-10.6-MDEV-25822)
Author: Sergei Petrunia <sergey@mariadb.com>
Date: Tue Jul 23 14:33:33 2024 +0300
MDEV-25822 JSON_TABLE: default values should allow non-string literals
(Polished initial patch by Alexey Botchkov)
Make the code handle DEFAULT values of any datatype
- Make Json_table_column::On_response::m_default be Item*, not LEX_STRING.
- Change the parser to use string literal non-terminals for producing
the DEFAULT value
-- Also, stop updating json_table->m_text_literal_cs for the DEFAULT
value literals as it is not used.
Need to check which version to push this into