• Log inStart now

NRQL syntax, clauses, and functions

NRQL is a query language you can use to query the New Relic database. This document explains NRQL syntax, clauses, components, and functions.

Syntax

This resource contains explanations for the various functions and clauses available for use in a NRQL query. Other popular resources for understanding NRQL include:

Query components

Every NRQL query will begin with a SELECT statement or a FROM clause. All other clauses are optional. The clause definitions below also contain example NRQL queries.

Required clauses

Optional clauses

Query metric data

Metric data is more complex than other types of data. There are specific tips for querying it well. We have two types of metric data, each with their own query guidelines:

For more details about how we report metric data, see Metric data types.

Functions

In this section we explain NRQL functions, both aggregator functions and non-aggregator functions.

Aggregator functions

You can use aggregator functions to filter and aggregate data. Some tips for using these:

Examples:

SELECT histogram(duration, 10, 20) FROM PageView SINCE 1 week ago

Non-aggregator functions

Use non-aggregator functions for non-numerical data in NRQL queries.

Type conversion

NRQL does not support "coercion." This means that a float stored as a string is treated as a string and cannot be operated on by functions expecting float values.

You can convert a string with a numeric value or a boolean with a string value to their numeric and boolean equivalents, or convert a non-string value to a string value, with these functions:

  • Use the numeric() function to convert a number with a string format to a numeric value. The function can be built into a query that uses math functions on query results or NRQL aggregator functions, such as average().
  • Use the boolean() function to convert a string value of "true" or "false" to the corresponding boolean value.
  • Use the string() function to convert a numeric, boolean, tuple, or array value to a string value. See string() above for more information.
Copyright © 2022 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.