Skip to content

Commit 88a81f4

Browse files
authored
Merge pull request #246064 from seesharprun/cosmos-populate-nosql-10
Cosmos DB | Add NoSQL query functions #12
2 parents 63fb2c7 + 8d0357f commit 88a81f4

File tree

6 files changed

+162
-314
lines changed

6 files changed

+162
-314
lines changed
Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,55 @@
11
---
2-
title: TicksToDateTime in Azure Cosmos DB query language
3-
description: Learn about SQL system function TicksToDateTime in Azure Cosmos DB.
4-
author: seesharprun
2+
title: TicksToDateTime
3+
titleSuffix: Azure Cosmos DB for NoSQL
4+
description: An Azure Cosmos DB for NoSQL system function that returns the number of ticks as a date and time value.
5+
author: jcodella
6+
ms.author: jacodel
7+
ms.reviewer: sidandrews
58
ms.service: cosmos-db
69
ms.subservice: nosql
7-
ms.topic: conceptual
8-
ms.date: 08/18/2020
9-
ms.author: sidandrews
10-
ms.reviewer: jucocchi
11-
ms.custom: query-reference, ignite-2022
10+
ms.topic: reference
11+
ms.date: 07/24/2023
12+
ms.custom: query-reference
1213
---
13-
# TicksToDateTime (Azure Cosmos DB)
14+
15+
# TicksToDateTime (NoSQL query)
16+
1417
[!INCLUDE[NoSQL](../../includes/appliesto-nosql.md)]
1518

16-
Converts the specified ticks value to a DateTime.
17-
19+
Converts the specified number of ticks to a date and time value.
20+
1821
## Syntax
19-
22+
2023
```sql
21-
TicksToDateTime (<Ticks>)
24+
TicksToDateTime(<numeric_expr>)
2225
```
2326

2427
## Arguments
2528

26-
*Ticks*
29+
| | Description |
30+
| --- | --- |
31+
| **`numeric_expr`** | A numeric expression. |
2732

28-
A signed numeric value, the current number of 100 nanosecond ticks that have elapsed since the Unix epoch. In other words, it is the number of 100 nanosecond ticks that have elapsed since 00:00:00 Thursday, 1 January 1970.
33+
> [!NOTE]
34+
> For more information on the ISO 8601 format, see [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601).
2935
3036
## Return types
3137

32-
Returns the UTC date and time ISO 8601 string value in the format `YYYY-MM-DDThh:mm:ss.fffffffZ` where:
33-
34-
|Format|Description|
35-
|-|-|
36-
|YYYY|four-digit year|
37-
|MM|two-digit month (01 = January, etc.)|
38-
|DD|two-digit day of month (01 through 31)|
39-
|T|signifier for beginning of time elements|
40-
|hh|two-digit hour (00 through 23)|
41-
|mm|two-digit minutes (00 through 59)|
42-
|ss|two-digit seconds (00 through 59)|
43-
|.fffffff|seven-digit fractional seconds|
44-
|Z|UTC (Coordinated Universal Time) designator|
45-
46-
For more information on the ISO 8601 format, see [ISO_8601](https://en.wikipedia.org/wiki/ISO_8601)
38+
Returns a UTC date and time string in the ISO 8601 format `YYYY-MM-DDThh:mm:ss.fffffffZ`.
4739

48-
## Remarks
40+
## Examples
4941

50-
TicksToDateTime will return `undefined` if the ticks value specified is invalid.
42+
The following example converts the ticks to a date and time value.
5143

52-
## Examples
53-
54-
The following example converts the ticks to a DateTime:
44+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/tickstodatetime/query.sql" highlight="2-4":::
5545

56-
```sql
57-
SELECT TicksToDateTime(15943368134575530) AS DateTime
58-
```
46+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/tickstodatetime/result.json":::
47+
48+
## Remarks
5949

60-
```json
61-
[
62-
{
63-
"DateTime": "2020-07-09T23:20:13.4575530Z"
64-
}
65-
]
66-
```
50+
- This function returns `undefined` if the ticks value specified is invalid.
6751

6852
## Next steps
6953

7054
- [System functions Azure Cosmos DB](system-functions.yml)
71-
- [Introduction to Azure Cosmos DB](../../introduction.md)
55+
- [`TimestampToDateTime`](timestamptodatetime.md)
Lines changed: 26 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,55 @@
11
---
2-
title: TimestampToDateTime in Azure Cosmos DB query language
3-
description: Learn about SQL system function TimestampToDateTime in Azure Cosmos DB.
4-
author: seesharprun
2+
title: TimestampToDateTime
3+
titleSuffix: Azure Cosmos DB for NoSQL
4+
description: An Azure Cosmos DB for NoSQL system function that returns the timestamp as a date and time value.
5+
author: jcodella
6+
ms.author: jacodel
7+
ms.reviewer: sidandrews
58
ms.service: cosmos-db
69
ms.subservice: nosql
7-
ms.topic: conceptual
8-
ms.date: 10/27/2022
9-
ms.author: sidandrews
10-
ms.reviewer: jucocchi
11-
ms.custom: query-reference, ignite-2022
10+
ms.topic: reference
11+
ms.date: 07/24/2023
12+
ms.custom: query-reference
1213
---
1314

14-
# TimestampToDateTime (Azure Cosmos DB)
15+
# TimestampToDateTime (NoSQL query)
1516

1617
[!INCLUDE[NoSQL](../../includes/appliesto-nosql.md)]
1718

18-
Converts the specified timestamp value to a DateTime.
19-
19+
Converts the specified timestamp to a date and time value.
20+
2021
## Syntax
21-
22+
2223
```sql
23-
TimestampToDateTime (<Timestamp>)
24+
TimestampToDateTime(<numeric_expr>)
2425
```
2526

2627
## Arguments
2728

28-
### Timestamp
29+
| | Description |
30+
| --- | --- |
31+
| **`numeric_expr`** | A numeric expression. |
2932

30-
A signed numeric value, the current number of milliseconds that have elapsed since the Unix epoch. In other words, the number of milliseconds that have elapsed since 00:00:00 Thursday, 1 January 1970.
33+
> [!NOTE]
34+
> For more information on the ISO 8601 format, see [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601).
3135
3236
## Return types
3337

34-
Returns the UTC date and time ISO 8601 string value in the format `YYYY-MM-DDThh:mm:ss.fffffffZ` where:
35-
36-
|Format|Description|
37-
|-|-|
38-
|YYYY|four-digit year|
39-
|MM|two-digit month (01 = January, etc.)|
40-
|DD|two-digit day of month (01 through 31)|
41-
|T|signifier for beginning of time elements|
42-
|hh|two-digit hour (00 through 23)|
43-
|mm|two-digit minutes (00 through 59)|
44-
|ss|two-digit seconds (00 through 59)|
45-
|.fffffff|seven-digit fractional seconds|
46-
|Z|UTC (Coordinated Universal Time) designator|
47-
48-
For more information on the ISO 8601 format, see [ISO_8601](https://en.wikipedia.org/wiki/ISO_8601)
49-
50-
## Remarks
51-
52-
TimestampToDateTime will return `undefined` if the timestamp value specified is invalid.
38+
Returns a UTC date and time string in the ISO 8601 format `YYYY-MM-DDThh:mm:ss.fffffffZ`.
5339

5440
## Examples
55-
56-
The following example converts the value `1,594,227,912,345` from milliseconds to a date and time of **July 8, 2020, 5:05 PM UTC**.
5741

58-
```sql
59-
SELECT TimestampToDateTime(1594227912345) AS DateTime
60-
```
42+
The following example converts the ticks to a date and time value.
6143

62-
```json
63-
[
64-
{
65-
"DateTime": "2020-07-08T17:05:12.3450000Z"
66-
}
67-
]
68-
```
44+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/timestamptodatetime/query.sql" highlight="2-4":::
6945

70-
This next example uses the timestamp from an existing item in a container. The item's timestamp is expressed in seconds.
46+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/timestamptodatetime/result.json":::
7147

72-
```json
73-
{
74-
"id": "8cc56bd4-5b8d-450b-a576-449836171398",
75-
"type": "reading",
76-
"data": "temperature",
77-
"value": 35.726545156,
78-
"_ts": 1605862991
79-
}
80-
```
81-
82-
To use the `_ts` value, you must multiply the value by 1,000 since the timestamp is expressed in seconds.
83-
84-
```sql
85-
SELECT
86-
TimestampToDateTime(r._ts * 1000) AS timestamp,
87-
r.id
88-
FROM
89-
readings r
90-
```
48+
## Remarks
9149

92-
```json
93-
[
94-
{
95-
"timestamp": "2020-11-20T09:03:11.0000000Z",
96-
"id": "8cc56bd4-5b8d-450b-a576-449836171398"
97-
}
98-
]
99-
```
50+
- This function returns `undefined` if the timestamp value specified is invalid.
10051

10152
## Next steps
10253

10354
- [System functions Azure Cosmos DB](system-functions.yml)
104-
- [Introduction to Azure Cosmos DB](../../introduction.md)
55+
- [`TicksToDateTime`](tickstodatetime.md)
Lines changed: 32 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,52 @@
11
---
2-
title: ToString in Azure Cosmos DB query language
3-
description: Learn about SQL system function ToString in Azure Cosmos DB.
4-
author: ginamr
2+
title: ToString
3+
titleSuffix: Azure Cosmos DB for NoSQL
4+
description: An Azure Cosmos DB for NoSQL system function that returns a value converted to a string.
5+
author: jcodella
6+
ms.author: jacodel
7+
ms.reviewer: sidandrews
58
ms.service: cosmos-db
69
ms.subservice: nosql
7-
ms.topic: conceptual
8-
ms.date: 03/04/2020
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
1113
---
12-
# ToString (Azure Cosmos DB)
14+
15+
# ToString (NoSQL query)
16+
1317
[!INCLUDE[NoSQL](../../includes/appliesto-nosql.md)]
1418

15-
Returns a string representation of scalar expression.
16-
19+
Returns a string representation of a value.
20+
1721
## Syntax
18-
22+
1923
```sql
2024
ToString(<expr>)
21-
```
22-
25+
```
26+
2327
## Arguments
24-
25-
*expr*
26-
Is any scalar expression.
27-
28+
29+
| | Description |
30+
| --- | --- |
31+
| **`expr`** | Any expression. |
32+
2833
## Return types
29-
30-
Returns a string expression.
31-
34+
35+
Returns a string expression.
36+
3237
## Examples
33-
34-
The following example shows how `ToString` behaves across different types.
35-
36-
```sql
37-
SELECT
38-
ToString(1.0000) AS str1,
39-
ToString("Hello World") AS str2,
40-
ToString(NaN) AS str3,
41-
ToString(Infinity) AS str4,
42-
ToString(IS_STRING(ToString(undefined))) AS str5,
43-
ToString(0.1234) AS str6,
44-
ToString(false) AS str7,
45-
ToString(undefined) AS str8
46-
```
47-
48-
Here is the result set.
49-
50-
```json
51-
[{"str1": "1", "str2": "Hello World", "str3": "NaN", "str4": "Infinity", "str5": "false", "str6": "0.1234", "str7": "false"}]
52-
```
53-
Given the following input:
54-
```json
55-
{"Products":[{"ProductID":1,"Weight":4,"WeightUnits":"lb"},{"ProductID":2,"Weight":32,"WeightUnits":"kg"},{"ProductID":3,"Weight":400,"WeightUnits":"g"},{"ProductID":4,"Weight":8999,"WeightUnits":"mg"}]}
56-
```
57-
The following example shows how `ToString` can be used with other string functions like `CONCAT`.
58-
59-
```sql
60-
SELECT
61-
CONCAT(ToString(p.Weight), p.WeightUnits)
62-
FROM p in c.Products
63-
```
64-
65-
Here is the result set.
66-
67-
```json
68-
[{"$1":"4lb" },
69-
{"$1":"32kg"},
70-
{"$1":"400g" },
71-
{"$1":"8999mg" }]
72-
73-
```
74-
Given the following input.
75-
```json
76-
{"id":"08259","description":"Cereals ready-to-eat, KELLOGG, KELLOGG'S CRISPIX","nutrients":[{"id":"305","description":"Caffeine","units":"mg"},{"id":"306","description":"Cholesterol, HDL","nutritionValue":30,"units":"mg"},{"id":"307","description":"Sodium, NA","nutritionValue":612,"units":"mg"},{"id":"308","description":"Protein, ABP","nutritionValue":60,"units":"mg"},{"id":"309","description":"Zinc, ZN","nutritionValue":null,"units":"mg"}]}
77-
```
78-
The following example shows how `ToString` can be used with other string functions like `REPLACE`.
79-
```sql
80-
SELECT
81-
n.id AS nutrientID,
82-
REPLACE(ToString(n.nutritionValue), "6", "9") AS nutritionVal
83-
FROM food
84-
JOIN n IN food.nutrients
85-
```
86-
Here is the result set:
8738

88-
```json
89-
[{"nutrientID":"305"},
90-
{"nutrientID":"306","nutritionVal":"30"},
91-
{"nutrientID":"307","nutritionVal":"912"},
92-
{"nutrientID":"308","nutritionVal":"90"},
93-
{"nutrientID":"309","nutritionVal":"null"}]
94-
```
39+
This example converts multiple scalar and object values to a string.
40+
41+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/tostring/query.sql" highlight="2-10":::
42+
43+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/tostring/result.json":::
9544

9645
## Remarks
9746

98-
This system function will not utilize the index.
47+
- This function doesn't use the index.
9948

10049
## Next steps
10150

10251
- [System functions Azure Cosmos DB](system-functions.yml)
103-
- [Introduction to Azure Cosmos DB](../../introduction.md)
52+
- [`IS_OBJECT`](is-object.md)

0 commit comments

Comments
 (0)