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
When querying _nested object fields_ using dot syntax, make sure to add the [`^`](https://clickhouse.com/docs/sql-reference/data-types/newjson#reading-json-sub-objects-as-sub-columns) operator:
114
+
115
+
```sql title="Query"
116
+
SELECT _full_document.^shipping as shipping_info FROM t1;
In ClickHouse, each field in JSON has `Dynamic` type. Dynamic type allows ClickHouse to store values of any type without knowing the type in advance. You can verify this with the `toTypeName` function:
@@ -218,9 +230,7 @@ SELECT
218
230
CAST(_full_document.status, 'String') AS status,
219
231
CAST(_full_document.total_amount, 'Decimal64(2)') AS total_amount,
220
232
CAST(parseDateTime64BestEffortOrNull(_full_document.order_date, 3), 'DATETIME(3)') AS order_date,
221
-
CAST(_full_document.shipping.method, 'String') AS shipping_method,
222
-
CAST(_full_document.shipping.city, 'String') AS shipping_city,
223
-
CAST(_full_document.shipping.cost, 'Decimal64(2)') AS shipping_cost,
233
+
_full_document.^shipping AS shipping_info,
224
234
_full_document.itemsAS items
225
235
FROM t1 FINAL
226
236
WHERE _peerdb_is_deleted =0;
@@ -236,9 +246,7 @@ This view will have the following schema:
236
246
│ status │ String │
237
247
│ total_amount │ Decimal(18, 2) │
238
248
│ order_date │ DateTime64(3) │
239
-
│ shipping_method │ String │
240
-
│ shipping_city │ String │
241
-
│ shipping_cost │ Decimal(18, 2) │
249
+
│ shipping_info │ JSON │
242
250
│ items │ Dynamic │
243
251
└─────────────────┴────────────────┘
244
252
```
@@ -250,7 +258,7 @@ SELECT
250
258
customer_id,
251
259
sum(total_amount)
252
260
FROM v1
253
-
WHEREshipping_city='Seattle'
261
+
WHEREshipping_info.city='Seattle'
254
262
GROUP BY customer_id
255
263
ORDER BY customer_id DESC
256
264
LIMIT10;
@@ -272,9 +280,7 @@ CREATE TABLE flattened_t1 (
272
280
`status` String,
273
281
`total_amount`Decimal(18, 2),
274
282
`order_date` DateTime64(3),
275
-
`shipping_method` String,
276
-
`shipping_city` String,
277
-
`shipping_cost`Decimal(18, 2),
283
+
`shipping_info` JSON,
278
284
`items` Dynamic
279
285
)
280
286
ENGINE = ReplacingMergeTree()
@@ -289,9 +295,7 @@ SELECT
289
295
CAST(_full_document.status, 'String') AS status,
290
296
CAST(_full_document.total_amount, 'Decimal64(2)') AS total_amount,
291
297
CAST(parseDateTime64BestEffortOrNull(_full_document.order_date, 3), 'DATETIME(3)') AS order_date,
292
-
CAST(_full_document.shipping.method, 'String') AS shipping_method,
293
-
CAST(_full_document.shipping.city, 'String') AS shipping_city,
294
-
CAST(_full_document.shipping.cost, 'Decimal64(2)') AS shipping_cost,
0 commit comments