Skip to content

Commit 6658030

Browse files
authored
Merge pull request #806 from Iceber/fix_mysql
internalstorage: fix json builder func for mysql
2 parents 1d4bd11 + ebb9188 commit 6658030

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pkg/storage/internalstorage/json_builder.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ func (jsonUpdate *JSONUpdateExpression) Build(builder clause.Builder) {
2828
var rawSQL string
2929
var values []interface{}
3030
switch stmt.Dialector.Name() {
31-
case "mysql", "sqlite3", "sqlite":
32-
rawSQL = fmt.Sprintf("JSON_SET(COALESCE(%s, '{}'), ?, JSON(?))", jsonUpdate.column)
31+
case "mysql":
32+
rawSQL = fmt.Sprintf("JSON_SET(COALESCE(%s, JSON_OBJECT()), ?, CAST(? AS JSON))", jsonUpdate.column)
33+
values = []interface{}{fmt.Sprintf(`$."%s"`, jsonUpdate.key), string(jsonUpdate.value)}
34+
case "sqlite3", "sqlite":
35+
rawSQL = fmt.Sprintf("JSON_SET(COALESCE(%s, JSON_OBJECT()), ?, JSON(?))", jsonUpdate.column)
3336
values = []interface{}{fmt.Sprintf(`$."%s"`, jsonUpdate.key), string(jsonUpdate.value)}
3437
case "postgres":
3538
rawSQL = fmt.Sprintf("JSONB_SET(COALESCE(%s, '{}'), ?, ?, true)", jsonUpdate.column)

0 commit comments

Comments
 (0)