- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
SQL in Analysis cells allows you to analyze and manipulate data within Log Workspaces. This documentation covers the SQL support available in Log Workspaces and includes:
The following SQL syntax is supported:
Syntax | Description | Example |
---|---|---|
SELECT (DISTINCT) DISTINCT: Optional | Retrieves rows from a database, with DISTINCT filtering out duplicate records. |
|
JOIN | Combines rows from two or more tables based on a related column between them. Supports FULL JOIN, INNER JOIN, LEFT JOIN, RIGHT JOIN. |
|
GROUP BY | Groups rows that have the same values in specified columns into summary rows. |
|
WHERE Includes support for LIKE , IN , ON , OR filters. | Filters records that meet a specified condition. |
|
CASE | Provides conditional logic to return different values based on specified conditions. |
|
WINDOW | Performs a calculation across a set of table rows that are related to the current row. |
|
IS NULL / IS NOT NULL | Checks if a value is null or not null. |
|
LIMIT | Specifies the maximum number of records to return. |
|
ORDER BY | Sorts the result set of a query by one or more columns. Includes ASC, DESC for sorting order. |
|
HAVING | Filters records that meet a specified condition after grouping. |
|
IN , ON , OR | Used for specified conditions in queries. Available in WHERE , JOIN clauses. |
|
AS | Renames a column or table with an alias. |
|
Arithmetic Operations | Performs basic calculations using operators like + , - , * , / . |
|
INTERVAL value unit | interval | Represents a time duration specified in a given unit. Supported units: - milliseconds / millisecond - seconds / second - minutes / minute - hours / hour - days / day |
The following SQL functions are supported. For Window function, see the separate Window function section in this documentation.
Function | Return Type | Description |
---|---|---|
min(variable v) | typeof v | Returns the smallest value in a set of data. |
max(variable v) | typeof v | Returns the maximum value across all input values. |
count(any a) | numeric | Returns the number of input values that are not null. |
sum(numeric n) | numeric | Returns the summation across all input values. |
avg(numeric n) | numeric | Returns the average value (arithmetic mean) across all input values. |
ceil(numeric n) | numeric | Returns the value rounded up to the nearest integer. |
floor(numeric n) | numeric | Returns the value rounded down to the nearest integer. |
round(numeric n) | numeric | Returns the value rounded to the nearest integer. |
lower(string s) | string | Returns the string as lowercase. |
upper(string s) | string | Returns the string as uppercase. |
abs(numeric n) | numeric | Returns the absolute value. |
coalesce(args a) | typeof first non-null a OR null | Returns the first non-null value or null if all are null. |
cast(value AS type) | type | Converts the given value to the specified data type. |
length(string s) | integer | Returns the number of characters in the string. |
trim(string s) | string | Removes leading and trailing whitespace from the string. |
replace(string s, string from, string to) | string | Replaces occurrences of a substring within a string with another substring. |
substring(string s, int start, int length) | string | Extracts a substring from a string, starting at a given position and for a specified length. |
strpos(string s, string substring) | integer | Returns the first index position of the substring in a given string, or 0 if there is no match. |
split_part(string s, string delimiter, integer index) | string | Splits the string on the given delimiter and returns the string at the given position counting from one. |
extract(unit from timestamp/interval) | numeric | Extracts a part of a date or time field (such as year or month) from a timestamp or interval. |
to_timestamp(string timestamp, string format) | timestamp | Converts a string to a timestamp according to the given format. |
to_char(timestamp t, string format) | string | Converts a timestamp to a string according to the given format. |
date_trunc(string unit, timestamp t) | timestamp | Truncates a timestamp to a specified precision based on the provided unit. |
regexp_like(string s, pattern p) | boolean | Evaluates whether a string matches a regular expression pattern. |
cardinality(array a) | integer | Returns the number of elements in the array. |
array_position(array a, typeof_array value) | integer | Returns the index of the first occurrence of the value found in the array, or null if value is not found. |
string_to_array(string s, string delimiter) | array of strings | Splits the given string into an array of strings using the given delimiter. |
array_agg(expression e) | array of input type | Creates an array by collecting all the input values. |
unnest(array a [, array b...]) | rows of a [, b…] | Expands arrays into a set of rows. This form is only allowed in a FROM clause. |
MIN
SELECT MIN(response_time) AS min_response_time
FROM logs
WHERE status_code = 200
MAX
SELECT MAX(response_time) AS max_response_time
FROM logs
WHERE status_code = 200
COUNT
SELECT COUNT(request_id) AS total_requests
FROM logs
WHERE status_code = 200
SUM
SELECT SUM(bytes_transferred) AS total_bytes
FROM logs
GROUP BY service_name
AVG
SELECT AVG(response_time)
AS avg_response_time
FROM logs
WHERE status_code = 200
GROUP BY service_name
CEIL
SELECT CEIL(price) AS rounded_price
FROM products
FLOOR
SELECT FLOOR(price) AS floored_price
FROM products
ROUND
SELECT ROUND(price) AS rounded_price
FROM products
LOWER
SELECT LOWER(customer_name) AS lowercase_name
FROM customers
UPPER
SELECT UPPER(customer_name) AS uppercase_name
FROM customers
ABS
SELECT ABS(balance) AS absolute_balance
FROM accounts
COALESCE
SELECT COALESCE(phone_number, email) AS contact_info
FROM users
CAST
Supported cast target types:
BIGINT
DECIMAL
TIMESTAMP
VARCHAR
SELECT
CAST(order_id AS VARCHAR) AS order_id_string,
'Order-' || CAST(order_id AS VARCHAR) AS order_label
FROM
orders
LENGTH
SELECT
customer_name,
LENGTH(customer_name) AS name_length
FROM
customers
INTERVAL
SELECT
TIMESTAMP '2023-10-01 10:00:00' + INTERVAL '30 days' AS future_date,
INTERVAL '1 MILLISECOND 2 SECONDS 3 MINUTES 4 HOURS 5 DAYS'
TRIM
SELECT
TRIM(name) AS trimmed_name
FROM
users
REPLACE
SELECT
REPLACE(description, 'old', 'new') AS updated_description
FROM
products
SUBSTRING
SELECT
SUBSTRING(title, 1, 10) AS short_title
FROM
books
STRPOS
SELECT
STRPOS('foobar', 'bar')
SPLIT_PART
SELECT
SPLIT_PART('aaa-bbb-ccc', '-', 2)
EXTRACT
Supported extraction units:
Literal | Input Type | Description |
---|---|---|
day | timestamp / interval | day of the month |
dow | timestamp | day of the week 1 (Monday) to 7 (Sunday) |
doy | timestamp | day of the year (1 - 366 ) |
hour | timestamp / interval | hour of the day (0 - 23 ) |
minute | timestamp / interval | minute of the hour (0 - 59 ) |
second | timestamp / interval | second of the minute (0 - 59 ) |
week | timestamp | week of the year (1 - 53 ) |
month | timestamp | month of the year (1 - 12 ) |
quarter | timestamp | quarter of the year (1 - 4 ) |
year | timestamp | year |
timezone_hour | timestamp | hour of the time zone offset |
timezone_minute | timestamp | minute of the time zone offset |
SELECT
EXTRACT(year FROM purchase_date) AS purchase_year
FROM
sales
TO_TIMESTAMP
Supported patterns for date/time formatting:
Pattern | Description |
---|---|
YYYY | year (4 digits) |
YY | year (2 digits) |
MM | month number (01 - 12) |
DD | day of month (01 - 31) |
HH24 | hour of day (00 - 23) |
HH12 | hour of day (01 - 12) |
HH | hour of day (01 - 12) |
MI | minute (00 - 59) |
SS | second (00 - 59) |
MS | millisecond (000 - 999) |
TZ | time-zone abbreviation |
OF | time-zone offset from UTC |
AM / am | meridiem indicator (without periods) |
PM / pm | meridiem indicator (without periods) |
SELECT
TO_TIMESTAMP('25/12/2025 04:23 pm', 'DD/MM/YYYY HH:MI am') AS ts
TO_CHAR
Supported patterns for date/time formatting:
Pattern | Description |
---|---|
YYYY | year (4 digits) |
YY | year (2 digits) |
MM | month number (01 - 12) |
DD | day of month (01 - 31) |
HH24 | hour of day (00 - 23) |
HH12 | hour of day (01 - 12) |
HH | hour of day (01 - 12) |
MI | minute (00 - 59) |
SS | second (00 - 59) |
MS | millisecond (000 - 999) |
TZ | time-zone abbreviation |
OF | time-zone offset from UTC |
AM / am | meridiem indicator (without periods) |
PM / pm | meridiem indicator (without periods) |
SELECT
TO_CHAR(order_date, 'MM-DD-YYYY') AS formatted_date
FROM
orders
DATE_TRUNC
Supported truncations:
milliseconds
seconds
/ second
minutes
/ minute
hours
/ hour
days
/ day
weeks
/ week
months
/ month
quarters
/ quarter
years
/ year
SELECT
DATE_TRUNC('month', event_time) AS month_start
FROM
events
REGEXP_LIKE
SELECT
*
FROM
emails
WHERE
REGEXP_LIKE(email_address, '@example\.com$')
CARDINALITY
SELECT
CARDINALITY(recipients)
FROM
emails
ARRAY_POSITION
SELECT
ARRAY_POSITION(recipients, 'hello@example.com')
FROM
emails
STRING_TO_ARRAY
SELECT
STRING_TO_ARRAY('a,b,c,d,e,f', ',')
ARRAY_AGG
SELECT
sender,
ARRAY_AGG(subject) subjects,
ARRAY_AGG(ALL subject) all_subjects,
ARRAY_AGG(DISTINCT subject) distinct_subjects
FROM
emails
GROUP BY
sender
UNNEST
SELECT
sender,
recipient
FROM
emails,
UNNEST(recipients) AS recipient
This table provides an overview of the supprted window functions. For comprehensive details and examples, see to the PostgreSQL documentation.
Function | Return Type | Description |
---|---|---|
over | N/A | Defines a window for a set of rows for other window functions to operate on. |
partition by | N/A | Divides the result set into partitions, specifically for applying window functions. |
rank() | integer | Assigns a rank to each row within a partition, with gaps for ties. |
row_number() | integer | Assigns a unique sequential number to each row within a partition. |
lead(column n) | typeof column | Returns the value from the next row in the partition. |
lag(column n) | typeof column | Returns the value from the previous row in the partition. |
first_value(column n) | typeof column | Returns the first value in an ordered set of values. |
last_value(column n) | typeof column | Returns the last value in an ordered set of values. |
nth_value(column n, offset) | typeof column | Returns the value at the specified offset in an ordered set of values. |
추가 유용한 문서, 링크 및 기사: