- 필수 기능
- 시작하기
- 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. |
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, from_string s1, to_string s2) | string | Replaces occurrences of a substring within a string with another substring. |
substring(string s, start_position_int i, length_int l) | string | Extracts a substring from a string, starting at a given position and for a specified length. |
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. |
to_timestamp(numeric n) | timestamp with time zone | Converts a numeric value to a timestamp with time zone. |
to_char(timestamp t / interval i / numeric n, format f) | string | Converts a timestamp, interval, or numeric value to a string using a format. |
date_trunc(field f, source [, time_zone]) | timestamp [with time zone] / interval | Truncates a timestamp or interval to a specified precision. |
regexp_like(string s, pattern p [flags]) | boolean | Evaluates if a string matches a regular expression pattern. |
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
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
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
EXTRACT
SELECT
extract(year FROM purchase_date) AS purchase_year
FROM
sales
TO_TIMESTAMP
SELECT
to_timestamp(epoch_time) AS formatted_time
FROM
event_logs
TO_CHAR
SELECT
to_char(order_date, 'MM-DD-YYYY') AS formatted_date
FROM
orders
DATE_TRUNC
SELECT
date_trunc('month', event_time) AS month_start
FROM
events
REGEXP_LIKE
SELECT
*
FROM
emails
WHERE
regexp_like(email_address, '@example\.com$')
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. |
추가 유용한 문서, 링크 및 기사: