• /
  • EnglishEspañol日本語한국어Português
  • Log inStart now

NRQL reference

To write good NRQL queries, it helps to understand how our various NRQL clauses and functions work. This doc contains definitions of NRQL clauses and functions, and gives examples of how to use them.

Looking for basic NRQL syntax rules? See How to use NRQL. For a tutorial, see Introductory NRQL tutorial.

Query components

As noted in our basic NRQL syntax doc, every NRQL query will contain a SELECT clause and a FROM clause, with all other clauses being 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(). Please note that if the NRQL value is in the gauge format, then numeric() won't work on it. Instead, you must use one of these compatible query functions:
  • latest()
  • min()
  • max()
  • sum()
  • count()
  • 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.

Comments

When writing a NRQL query, you can add comments, which can help your team members better understand and use the query.

Here are syntax details:

  • -- Two dashes will comment out all text to the right of this indicator on the same line.
  • // Two slashes will comment out all text to the right of this indicator on the same line.
  • /* */ Any text in between these character sets will be commented out. This indicator can apply to multiple lines.

Note that comments aren't displayed everywhere. Some views, like "recent queries" and "view query," won't show comments.

Some example queries that include comments:

FROM Transaction SELECT uniqueCount(appId) -- This will return the number of unique App IDs
FROM TransactionError
SELECT count(*) SINCE 1 day ago // Transaction Error for the past day
FROM TransactionTrace /* This data may be incomplete;
If so, run a query of Transaction */
SELECT count(*)

Other popular resources for understanding NRQL syntax and rules include:

Copyright © 2024 New Relic Inc.

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