diff options
author | solovboy <solovboy@yandex-team.com> | 2023-09-20 18:16:23 +0300 |
---|---|---|
committer | solovboy <solovboy@yandex-team.com> | 2023-09-20 18:42:22 +0300 |
commit | 92c39d27489fe47742f7fcf1e4076431fdfa5faf (patch) | |
tree | 8ace0d6dbdd7e910228cd3b51ae32516883913c4 | |
parent | 12375b89000c19f1b11c47bbe065c62c54016a86 (diff) | |
download | ydb-92c39d27489fe47742f7fcf1e4076431fdfa5faf.tar.gz |
Added an example of adding a JSON-string with escaping quotes
Added an example of adding a JSON-string with escaping quotes
-rw-r--r-- | ydb/docs/en/core/faq/_includes/yql.md | 15 | ||||
-rw-r--r-- | ydb/docs/ru/core/faq/_includes/yql.md | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/ydb/docs/en/core/faq/_includes/yql.md b/ydb/docs/en/core/faq/_includes/yql.md index 709db9f6e7a..99da7090b05 100644 --- a/ydb/docs/en/core/faq/_includes/yql.md +++ b/ydb/docs/en/core/faq/_includes/yql.md @@ -37,6 +37,21 @@ WHERE Key LIKE "some_prefix%"; 1000 rows is the response size limit per YQL query. If a response is shortened, it is flagged as `Truncated`. To output more table rows, you can use [paginated output](../../best_practices/paging.md) or the `ReadTable` operation. +#### How to escape quotes of JSON strings when adding them to a table? {#escaping-quotes} + +Consider an example with two possible options for adding a JSON string to a table: + +```sql +UPSERT INTO test_json(id, json_string) +VALUES + (1, Json(@@[{"name":"Peter \"strong cat\" Kourbatov"}]@@)), + (2, Json('[{"name":"Peter \\\"strong cat\\\" Kourbatov"}]')) +; +``` +To insert a value in the first line, use `raw string` and the escape method using `\"`. To insert the second line, escaping through `\\\"` is used. + +We recommend using `raw string` and the escape method using `\"`, as it is more visual. + #### How do I update only those values whose keys are not in the table? {#update-non-existent} You can use the `LEFT JOIN` operator to identify the keys a table is missing and update their values: diff --git a/ydb/docs/ru/core/faq/_includes/yql.md b/ydb/docs/ru/core/faq/_includes/yql.md index 2b978d40333..1efe5230796 100644 --- a/ydb/docs/ru/core/faq/_includes/yql.md +++ b/ydb/docs/ru/core/faq/_includes/yql.md @@ -37,6 +37,21 @@ WHERE Key LIKE "some_prefix%"; 1000 строк — ограничение на размер одного результата для YQL запроса. В случае если результат запроса был обрезан, он будет помечен флагом `Truncated`. Чтобы получить большее количество строк из таблицы, можно воспользоваться [постраничным выводом](../../best_practices/paging.md) или операцией `ReadTable`. +#### Как экранировать кавычки JSON-строк при добавлении их в таблицу? {#escaping-quotes} + +Рассмотрим пример c двумя возможными вариантами добавления JSON-строки в таблицу: + +```sql +UPSERT INTO test_json(id, json_string) +VALUES + (1, Json(@@[{"name":"Peter \"strong cat\" Kourbatov"}]@@)), + (2, Json('[{"name":"Peter \\\"strong cat\\\" Kourbatov"}]')) +; +``` +Для вставки значения в первой строке используется `raw string` и способ экранирования с помощью `\"`. Для вставки второй строки используется экранирование через `\\\"`. + +Мы рекомендуем применять `raw string` и способ экранирования с помощью `\"`, так как он более нагляден. + #### Как обновить только те значения, ключей которых нет в таблице? {#update-non-existent} Можно использовать операцию `LEFT JOIN`, чтобы пометить отсутствующие в таблице ключи, после чего обновить их значения: |