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

Incomplete and incorrect errors for arguments of JSON functions #53799

Closed
dveeden opened this issue Jun 4, 2024 · 2 comments · Fixed by #53800
Closed

Incomplete and incorrect errors for arguments of JSON functions #53799

dveeden opened this issue Jun 4, 2024 · 2 comments · Fixed by #53800
Assignees
Labels

Comments

@dveeden
Copy link
Contributor

dveeden commented Jun 4, 2024

Bug Report

Some JSON functions have errors where:

  • The error text differs from MySQL
  • The error has an incorrect number of arguments for the message
  • The error has an error code that differs from MySQL

1. Minimal reproduce step (Required)

SELECT JSON_CONTAINS(123, '');
SELECT JSON_CONTAINS('{}', 123);
SELECT JSON_OVERLAPS(123, '');
SELECT JSON_OVERLAPS('{}', 123);
SELECT 'abc' MEMBER OF(123);

2. What did you expect to see? (Required)

With MySQL 8.4.0

mysql> SELECT JSON_CONTAINS(123, '');
ERROR 3146 (22032): Invalid data type for JSON data in argument 1 to function json_contains; a JSON string or JSON type is required.
mysql> SELECT JSON_CONTAINS('{}', 123);
ERROR 3146 (22032): Invalid data type for JSON data in argument 2 to function json_contains; a JSON string or JSON type is required.
mysql> SELECT JSON_OVERLAPS(123, '');
ERROR 3146 (22032): Invalid data type for JSON data in argument 1 to function json_overlaps; a JSON string or JSON type is required.
mysql> SELECT JSON_OVERLAPS('{}', 123);
ERROR 3146 (22032): Invalid data type for JSON data in argument 2 to function json_overlaps; a JSON string or JSON type is required.
mysql> SELECT 'abc' MEMBER OF(123);
ERROR 3146 (22032): Invalid data type for JSON data in argument 2 to function member of; a JSON string or JSON type is required.

3. What did you see instead (Required)

mysql> SELECT JSON_CONTAINS(123, '');
ERROR 3069 (22032): Invalid JSON data provided to function %!s(int=1): json_contains
mysql> SELECT JSON_CONTAINS('{}', 123);
ERROR 3069 (22032): Invalid JSON data provided to function %!s(int=2): json_contains
mysql> SELECT JSON_OVERLAPS(123, '');
ERROR 3069 (22032): Invalid JSON data provided to function %!s(int=1): json_overlaps
mysql> SELECT JSON_OVERLAPS('{}', 123);
ERROR 3069 (22032): Invalid JSON data provided to function %!s(int=2): json_overlaps
mysql> SELECT 'abc' MEMBER OF(123);
ERROR 3069 (22032): Invalid JSON data provided to function %!s(int=2): member of

4. What is your TiDB version? (Required)

Release Version: v8.1.0
Edition: Community
Git Commit Hash: 945d07c5d5c7a1ae212f6013adfb187f2de24b23
Git Branch: HEAD
UTC Build Time: 2024-05-21 03:51:57
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv
@dveeden
Copy link
Contributor Author

dveeden commented Jun 4, 2024

Note that the SQL state is also wrong in some other functions like JSON_MERGE().

@dveeden dveeden added type/compatibility compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) labels Jun 4, 2024
@dveeden
Copy link
Contributor Author

dveeden commented Jun 6, 2024

I found another case:

mysql> SELECT JSON_SEARCH('{"name": {"first": "John", "last": "Doe"}, "type": "Person"}',3,4);
ERROR 3143 (42000): Invalid JSON path expression. The error is around character position %d.

@jebter jebter added the sig/sql-infra SIG: SQL Infra label Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants