|
1 | 1 | ---
|
2 |
| -title: TRIM in Azure Cosmos DB query language |
3 |
| -description: Learn about SQL system function TRIM in Azure Cosmos DB. |
4 |
| -author: ginamr |
| 2 | +title: TRIM |
| 3 | +titleSuffix: Azure Cosmos DB for NoSQL |
| 4 | +description: An Azure Cosmos DB for NoSQL system function that returns a string with leading or trailing whitespace trimmed. |
| 5 | +author: jcodella |
| 6 | +ms.author: jacodel |
| 7 | +ms.reviewer: sidandrews |
5 | 8 | ms.service: cosmos-db
|
6 | 9 | ms.subservice: nosql
|
7 |
| -ms.topic: conceptual |
8 |
| -ms.date: 09/14/2021 |
9 |
| -ms.author: girobins |
10 |
| -ms.custom: query-reference, ignite-2022 |
| 10 | +ms.topic: reference |
| 11 | +ms.date: 07/24/2023 |
| 12 | +ms.custom: query-reference |
11 | 13 | ---
|
12 |
| -# TRIM (Azure Cosmos DB) |
| 14 | + |
| 15 | +# TRIM (NoSQL query) |
| 16 | + |
13 | 17 | [!INCLUDE[NoSQL](../../includes/appliesto-nosql.md)]
|
14 | 18 |
|
15 |
| -Returns a string expression after it removes leading and trailing whitespace or specified characters. |
16 |
| - |
| 19 | +Returns a string expression after it removes leading and trailing whitespace or custom characters. |
| 20 | + |
17 | 21 | ## Syntax
|
18 |
| - |
| 22 | + |
19 | 23 | ```sql
|
20 |
| -TRIM(<str_expr1>[, <str_expr2>]) |
21 |
| -``` |
22 |
| - |
| 24 | +TRIM(<string_expr_1> [, <string_expr_2>]) |
| 25 | +``` |
| 26 | + |
23 | 27 | ## Arguments
|
24 |
| - |
25 |
| -*str_expr1* |
26 |
| - Is a string expression |
27 | 28 |
|
28 |
| -*str_expr2* |
29 |
| - Is an optional string expression to be trimmed from str_expr1. If not set, the default is whitespace. |
| 29 | +| | Description | |
| 30 | +| --- | --- | |
| 31 | +| **`string_expr_1`** | A string expression. | |
| 32 | +| **`string_expr_2` *(Optional)*** | An optional string expression with a string to trim from `string_expr_1`. If not specified, the default is to trim whitespace. | |
30 | 33 |
|
31 | 34 | ## Return types
|
32 |
| - |
33 |
| - Returns a string expression. |
34 |
| - |
| 35 | + |
| 36 | +Returns a string expression. |
| 37 | + |
35 | 38 | ## Examples
|
36 |
| - |
37 |
| - The following example shows how to use `TRIM` inside a query. |
38 |
| - |
39 |
| -```sql |
40 |
| -SELECT TRIM(" abc") AS t1, |
41 |
| -TRIM(" abc ") AS t2, |
42 |
| -TRIM("abc ") AS t3, |
43 |
| -TRIM("abc") AS t4, |
44 |
| -TRIM("abc", "ab") AS t5, |
45 |
| -TRIM("abc", "abc") AS t6 |
46 |
| -``` |
47 |
| - |
48 |
| - Here is the result set. |
49 |
| - |
50 |
| -```json |
51 |
| -[ |
52 |
| - { |
53 |
| - "t1": "abc", |
54 |
| - "t2": "abc", |
55 |
| - "t3": "abc", |
56 |
| - "t4": "abc", |
57 |
| - "t5": "c", |
58 |
| - "t6": "" |
59 |
| - } |
60 |
| -] |
61 |
| -``` |
| 39 | + |
| 40 | +This example illustrates various ways to trim a string expression. |
| 41 | + |
| 42 | +:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/trim/query.sql" highlight="2-9"::: |
| 43 | + |
| 44 | +:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/trim/result.json"::: |
62 | 45 |
|
63 | 46 | ## Remarks
|
64 | 47 |
|
65 |
| -This system function will not utilize the index. |
| 48 | +- This function doesn't use the index. |
66 | 49 |
|
67 | 50 | ## Next steps
|
68 | 51 |
|
69 | 52 | - [System functions Azure Cosmos DB](system-functions.yml)
|
70 |
| -- [Introduction to Azure Cosmos DB](../../introduction.md) |
| 53 | +- [`TRUNC`](trunc.md) |
0 commit comments