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

In the test cases in TiDB, MySQL and TiDB behave differently, whichever prevails #31104

Closed
Tracked by #36993
coolboydan opened this issue Dec 29, 2021 · 2 comments · Fixed by #37579
Closed
Tracked by #36993

In the test cases in TiDB, MySQL and TiDB behave differently, whichever prevails #31104

coolboydan opened this issue Dec 29, 2021 · 2 comments · Fixed by #37579
Assignees
Labels
component/json type/question The issue belongs to a question.

Comments

@coolboydan
Copy link

coolboydan commented Dec 29, 2021

General Question

In the test case util/admin/admin_integration_test.go:59

create table t1 (
		a int             as (JSON_EXTRACT(k,'$.a')),
		c double          as (JSON_EXTRACT(k,'$.c')),
		d decimal(20,10)  as (JSON_EXTRACT(k,'$.d')),
		e char(10)        as (JSON_EXTRACT(k,'$.e')),
		f date            as (JSON_EXTRACT(k,'$.f')),
		g time            as (JSON_EXTRACT(k,'$.g')),
		h datetime        as (JSON_EXTRACT(k,'$.h')),
		i timestamp       as (JSON_EXTRACT(k,'$.i')),
		j year            as (JSON_EXTRACT(k,'$.j')),
		k json);

insert into t1 set k='{"a": 100,"c":1.234,"d":1.2340000000,"e":"abcdefg","f":"2018-09-28","g":"12:59:59","h":"2018-09-28 12:59:59","i":"2018-09-28 16:40:33","j":"2018"}';

In TiDB it can write normally。

When executed in MySQL

mysql> insert into t1 set k='{"a": 100,"c":1.234,"d":1.2340000000,"e":"abcdefg","f":"2018-09-28","g":"12:59:59","h":"2018-09-28 12:59:59","i":"2018-09-28 16:40:33","j":"2018"}';
ERROR 3156 (22018): Invalid JSON value for CAST to DATE/TIME/DATETIME/TIMESTAMP from column json_extract at row 1

Which shall prevail

@coolboydan coolboydan added the type/question The issue belongs to a question. label Dec 29, 2021
@YangKeao YangKeao self-assigned this Aug 25, 2022
@xiongjiwei
Copy link
Contributor

maybe same root cause #25329

@YangKeao
Copy link
Member

YangKeao commented Sep 2, 2022

Same problem with #9988. In MySQL:

bool Json_wrapper::coerce_time(MYSQL_TIME *ltime,
                               const char *msgnam) const
{
  switch (type())
  {
  case Json_dom::J_DATETIME:
  case Json_dom::J_DATE:
  case Json_dom::J_TIME:
  case Json_dom::J_TIMESTAMP:
    set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME);
    get_datetime(ltime);
    return false;
  default:
    push_json_coercion_warning("DATE/TIME/DATETIME/TIMESTAMP",
                               ER_INVALID_JSON_VALUE_FOR_CAST, msgnam);
    return true;
  }
}

We cannot cast a json string value to DATE/TIME/DATETIME/TIMESTAMP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/json type/question The issue belongs to a question.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants