Skip to content
ClickHouse Docs
ClickHouse DocsClickHouse Docs

format

يحلّل البيانات من الوسيطات وفق تنسيق الإدخال المحدد. وإذا لم تُحدَّد وسيطة البنية، فستُستخلص من البيانات.

البنية

format(format_name, [structure], data)

الوسائط

  • format_nameتنسيق البيانات.
  • structure - بنية الجدول. اختياري. التنسيق: 'column1_name column1_type, column2_name column2_type, …'.
  • data — قيمة حرفية من نوع سلسلة نصية أو تعبير ثابت يُرجع سلسلة نصية تحتوي على بيانات بالتنسيق المحدد

القيمة المعادة

جدول يتضمن بيانات جرى تحليلها من الوسيطة data وفقًا للتنسيق المحدد والبنية المحددة أو المستخرجة.

أمثلة

بدون وسيطة structure:

Querysql
SELECT * FROM format(JSONEachRow,
$$
{"a": "Hello", "b": 111}
{"a": "World", "b": 123}
{"a": "Hello", "b": 112}
{"a": "World", "b": 124}
$$)
Responseresponse
┌───b─┬─a─────┐
│ 111 │ Hello │
│ 123 │ World │
│ 112 │ Hello │
│ 124 │ World │
└─────┴───────┘
Querysql
DESC format(JSONEachRow,
$$
{"a": "Hello", "b": 111}
{"a": "World", "b": 123}
{"a": "Hello", "b": 112}
{"a": "World", "b": 124}
$$)
Responseresponse
┌─name─┬─type──────────────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐
│ b    │ Nullable(Float64) │              │                    │         │                  │                │
│ a    │ Nullable(String)  │              │                    │         │                  │                │
└──────┴───────────────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘

باستخدام الوسيطة structure:

Querysql
SELECT * FROM format(JSONEachRow, 'a String, b UInt32',
$$
{"a": "Hello", "b": 111}
{"a": "World", "b": 123}
{"a": "Hello", "b": 112}
{"a": "World", "b": 124}
$$)
Responseresponse
┌─a─────┬───b─┐
│ Hello │ 111 │
│ World │ 123 │
│ Hello │ 112 │
│ World │ 124 │
└───────┴─────┘
Navigation