You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Selecting JSON when it is first cast to a string (::String). Must be scanned into a Go string type.
Selecting Dynamic column (from within a JSON object) when it is first cast to a string (::String). Must be scanned into a Go string type.
What doesn't work:
Inserting as Go json.RawMessage ([]byte) does not work (although I don't believe this works for String either)
Selecting does not work for non-casted JSON type column, the Go driver reports it as an unsupported type
Selecting does not work for non-casted Dynamic type column, the Go driver reports it as an unsupported type
Sample SQL:
SET allow_experimental_json_type =1;
CREATETABLEjson_test (id String, obj JSON) Engine = MergeTree ORDER BY id;
INSERT INTO json_test (id, obj) VALUES ('a', '{ "key1": "value1", "nestedKey2": { "nestedValue2": 5 }, "arrayKey3": [4, 5, 6] }')
SELECT id, obj.key1, obj.nestedKey2, obj.arrayKey3, obj.nestedKey2.nestedValue2, obj FROM json_test;
Sample code:
// regular structtypejsonRowstruct {
IDstring`ch:"id"`Objstring`ch:"obj"`
}
// row to insert, note that the JSON data is a `string`varinsertRow=jsonRow{
ID: "c",
Obj: `{ "key1": "value1", "nestedKey2": { "nestedValue2": 5 }, "arrayKey3": [4, 5, 6] }`,
}
// async insert, blockingerr=db.AsyncInsert(context.Background(), "INSERT INTO json_test (id, obj) VALUES (?, ?)", true, insertRow.ID, insertRow.Obj)
iferr!=nil {
fmt.Println(err)
return
}
// This is where things break. The JSON column MUST be cast to a string here.// Also renamed to fit struct tags.// If the JSON column is not cast to string, the following error is printed: clickhouse: unsupported column type "JSON"varrows []jsonRowerr=db.Select(context.Background(), &rows, "SELECT id, obj::String as obj FROM json_test")
iferr!=nil {
fmt.Println(err)
return
}
// Print objectfmt.Printf("%+v\n", rows)
// Output (formatted):// [{// ID: c// Obj: {"arrayKey3":["4","5","6"],"key1":"value1","nestedKey2":{"nestedValue2":"5"}}// }]
Example of selecting an object key in Grafana (which uses our latest Go driver):
The text was updated successfully, but these errors were encountered:
SOLVED: only works by appending SETTINGS output_format_json_quote_64bit_integers = 0 to the query; the same user-level setting did nothing.
Leaving the original below for future readers/googlers...
It's also problematic that selecting a JSON or Dynamic column with UInt64 (i.e., golang's int or int64) results in a string being returned even if the JSON field has the UInt64 type.
This doesn't change when using SET output_format_json_quote_64bit_integers = 0;
Scope:
Object('json')
from @SpencerTorres preliminary research
What works:
string
JSON
when it is first cast to a string (::String
). Must be scanned into a Gostring
type.Dynamic
column (from within aJSON
object) when it is first cast to a string (::String
). Must be scanned into a Gostring
type.What doesn't work:
json.RawMessage
([]byte
) does not work (although I don't believe this works forString
either)JSON
type column, the Go driver reports it as an unsupported typeDynamic
type column, the Go driver reports it as an unsupported typeSample SQL:
Sample code:
Example of selecting an object key in Grafana (which uses our latest Go driver):
The text was updated successfully, but these errors were encountered: