Skip to content

Commit 2f14858

Browse files
committed
Fix incorrect syntax for to_timestamp and add supported patterns
1 parent 0e7aea5 commit 2f14858

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

content/en/logs/workspaces/sql_reference.md

+21-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The following SQL functions are supported. For Window function, see the separate
9393
| `replace(string s, string from, string to)` | string | Replaces occurrences of a substring within a string with another substring. |
9494
| `substring(string s, int start, int length)` | string | Extracts a substring from a string, starting at a given position and for a specified length. |
9595
| `extract(field from timestamp/interval)` | numeric | Extracts a part of a date or time field (such as year or month) from a timestamp or interval. |
96-
| `to_timestamp(numeric n)` | timestamp with time zone | Converts a numeric value to a timestamp with time zone. |
96+
| `to_timestamp(string timestamp, string format)` | timestamp | Converts a string to a timestamp according to the given format. |
9797
| `to_char(timestamp t / interval i / numeric n, format f)` | string | Converts a timestamp, interval, or numeric value to a string using a format.|
9898
| `date_trunc(string unit, timestamp t)` | timestamp | Truncates a timestamp to a specified precision based on the provided unit. |
9999
| `regexp_like(string s, pattern p)` | boolean | Evaluates if a string matches a regular expression pattern. |
@@ -233,11 +233,28 @@ FROM
233233
{{< /code-block >}}
234234

235235
### `TO_TIMESTAMP`
236+
237+
Supported patterns for date/time formatting:
238+
| Pattern | Description |
239+
| ----------- | ------------------------------------ |
240+
| `YYYY` | year (4 digits) |
241+
| `YY` | year (2 digits) |
242+
| `MM` | month number (01 - 12) |
243+
| `DD` | day of month (01 - 31) |
244+
| `HH24` | hour of day (00 - 23) |
245+
| `HH12` | hour of day (01 - 12) |
246+
| `HH` | hour of day (01 - 12) |
247+
| `MI` | minute (00 - 59) |
248+
| `SS` | second (00 - 59) |
249+
| `MS` | millisecond (000 - 999) |
250+
| `TZ` | time-zone abbreviation |
251+
| `OF` | time-zone offset from UTC |
252+
| `AM` / `am` | meridiem indicator (without periods) |
253+
| `PM` / `pm` | meridiem indicator (without periods) |
254+
236255
{{< code-block lang="sql" >}}
237256
SELECT
238-
to_timestamp(epoch_time) AS formatted_time
239-
FROM
240-
event_logs
257+
to_timestamp('25/12/2025 04:23 pm', 'DD/MM/YYYY HH:MI am') AS ts
241258
{{< /code-block >}}
242259

243260
### `TO_CHAR`

0 commit comments

Comments
 (0)