@@ -568,12 +568,55 @@ defmodule Ch.ConnectionTest do
568568 } } = Ch . query ( conn , "SELECT * FROM t_uuid ORDER BY y" )
569569 end
570570
571+ # TODO non utf8
572+ test "read json as string" , % { conn: conn } do
573+ assert Ch . query! ( conn , ~s| select '{"a":42}'::JSON| , [ ] ,
574+ settings: [
575+ enable_json_type: 1 ,
576+ output_format_binary_write_json_as_string: 1
577+ ]
578+ ) . rows == [ [ % { "a" => "42" } ] ]
579+ end
580+
581+ test "write->read json as string" , % { conn: conn } do
582+ Ch . query! ( conn , "CREATE TABLE test_write_json(json JSON) ENGINE = Memory" , [ ] ,
583+ settings: [
584+ enable_json_type: 1
585+ ]
586+ )
587+
588+ rowbinary =
589+ Ch.RowBinary . encode_rows (
590+ [
591+ [ :json . encode ( % { "a" => 42 } ) ] ,
592+ [ :json . encode ( % { "b" => 10 } ) ]
593+ ] ,
594+ _types = [ :string ]
595+ )
596+
597+ Ch . query! ( conn , [ "insert into test_write_json(json) format RowBinary\n " | rowbinary ] , [ ] ,
598+ settings: [
599+ enable_json_type: 1 ,
600+ input_format_binary_read_json_as_string: 1
601+ ]
602+ )
603+
604+ assert Ch . query! ( conn , "select json from test_write_json" , [ ] ,
605+ settings: [
606+ enable_json_type: 1 ,
607+ output_format_binary_write_json_as_string: 1
608+ ]
609+ ) . rows ==
610+ [ [ % { "a" => "42" } ] , [ % { "b" => "10" } ] ]
611+ end
612+
571613 # https://clickhouse.com/docs/en/sql-reference/data-types/newjson
572614 # https://clickhouse.com/docs/en/integrations/data-formats/json/overview
573615 # https://clickhouse.com/blog/a-new-powerful-json-data-type-for-clickhouse
574616 # https://clickhouse.com/blog/json-bench-clickhouse-vs-mongodb-elasticsearch-duckdb-postgresql
575617 # https://github.com/ClickHouse/ClickHouse/pull/70288
576618 # https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/TypeId.h
619+ @ tag :skip
577620 test "json" , % { conn: conn } do
578621 settings = [ enable_json_type: 1 ]
579622
0 commit comments