diff --git a/db/dialect_clickhouse.go b/db/dialect_clickhouse.go index 9b9c6ed..bf114b1 100644 --- a/db/dialect_clickhouse.go +++ b/db/dialect_clickhouse.go @@ -190,22 +190,19 @@ func convertToType(value string, valueType reflect.Type) (any, error) { case reflect.String: return value, nil case reflect.Slice: - // in case the slice values are wrapped in single quotes replace them to use json.Unmarshal which requires double quotes - value = strings.ReplaceAll(value, "'", "\"") - var anySlice []any - if err := json.Unmarshal([]byte(value), &anySlice); err != nil { - return "", fmt.Errorf("could not unmarshal slice value %q: %w", value, err) + if valueType.Elem().Kind() == reflect.Struct || valueType.Elem().Kind() == reflect.Ptr { + return nil, fmt.Errorf("%q is not supported as Clickhouse Array type", valueType.Elem().Name()) } - for i, v := range anySlice { - convertedType, err := convertToType(fmt.Sprintf("%v", v), valueType.Elem()) - if err != nil { - return "", fmt.Errorf("converting value %q to type %q in column %q: %w", v, valueType.Elem(), i, err) - } - anySlice[i] = convertedType + // in case the slice values are wrapped in single quotes, replace them to use json.Unmarshal which requires double quotes + value = strings.ReplaceAll(value, "'", "\"") + + res := reflect.New(reflect.SliceOf(valueType.Elem())) + if err := json.Unmarshal([]byte(value), res.Interface()); err != nil { + return "", fmt.Errorf("could not unmarshal slice value %q: %w", value, err) } - return anySlice, nil + return res.Elem().Interface(), nil case reflect.Bool: return strconv.ParseBool(value) case reflect.Int: