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

Closed
hackersean opened this issue Jun 17, 2024 · 1 comment · Fixed by #54145
Closed
Assignees
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

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.

@ti-chi-bot ti-chi-bot bot added the affects-8.5 This bug affects the 8.5.x(LTS) versions. label Nov 1, 2024
@YangKeao YangKeao added affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. and removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 labels Nov 20, 2024
@ti-chi-bot ti-chi-bot bot closed this as completed in db4d19b Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants