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

Error 3144 (HY000): Cannot create a JSON value from a string with CHARACTER SET 'binary'. #54044

Open
hackersean opened this issue Jun 17, 2024 · 1 comment

Comments

@hackersean
Copy link
Contributor

Bug Report

the bug is same as MySQL, link

1. Minimal reproduce step (Required)

when use gorm in golang.

storage.DB().Model(filter).Where(filter).Where("JSON_CONTAINS(labels,JSON_OBJECT(?,?))", "flag", true).Find(&list).Error

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

The query result is displayed normally

3. What did you see instead (Required)

Error 3144 (HY000): Cannot create a JSON value from a string with CHARACTER SET 'binary'.

If concatenated into an SQL statement, it runs properly.

4. What is your TiDB version? (Required)

Release Version: v6.5.0
Edition: Community
Git Commit Hash: 706c3fa
Git Branch: heads/refs/tags/v6.5.0
UTC Build Time: 2022-12-27 03:50:44
GoVersion: go1.19.3
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv

@hackersean hackersean added the type/bug The issue is confirmed as a bug. label Jun 17, 2024
@jebter jebter added the sig/sql-infra SIG: SQL Infra label Jun 18, 2024
@YangKeao YangKeao self-assigned this Jun 20, 2024
@YangKeao
Copy link
Member

A reproduce:

package main

import (
	"fmt"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

type Item struct {
	gorm.Model
	Labels string
}

func main() {
	db, err := gorm.Open(mysql.New(mysql.Config{
		DSN: "root@tcp(127.0.0.1:4000)/test",
	}), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}

	db.AutoMigrate(&Item{})

	var filter Item

	var list []Item

	err = db.Model(&filter).Where("JSON_CONTAINS(labels, JSON_OBJECT(?, ?))", "flag", true).Find(&list).Error
	if err != nil {
		fmt.Println("Query error:", err)
		return
	}

	fmt.Println("Query results:", list)
}

It's not related to link, because this program runs well on MySQL.

The problem is that during PREPARE, the charset/collation of the first argument is binary. We know little about the correct collation/type during PREPARE, so maybe it's not correct to assert type and charset/collation in getFunction stage. There must be many similar issues, not only for JSON.

I'll try to find more similar issues and fix them all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants