preview
We're still working on this feature, but we'd love for you to try it out!
This feature is currently provided as part of a preview program pursuant to our pre-release policies.
You can write Lens queries in Query Builder, Notebooks, and custom dashboards. This page explains how to query data in each platform.
Tip
When querying data sources, Lens doesn't restrict the number of rows you can retrieve from external sources. However, queries to NRDB through Lens maintain the same 5,000 row limit as NRQL.
Prerequisites
Before you start:
- Verify you have the necessary permissions to query data sources.
- If you need to query external data sources, ensure the connectors are set up.
Query in the query builder
- Go to one.newrelic.com.
- From the drawer at the bottom of the page, open the Query your data console.
- In the query editor, select Lens data (SQL) as the query language.
- If you want to query NRDB data, select the account from the account selector. Other data connectors are available at the organization level and don't require account selection.
- Write your SQL query using the table reference format:
connection_name.schema.table - Click Run. The chart renders based on your query results.
Save query in Notebooks
Notebooks are shareable documents that combine queries, visualizations, and markdown documentation.
- Go to one.newrelic.com.
- From the drawer at the bottom of the page, open the Query your data console.
- Enable the toggle beside Notebooks. At the bottom of the page, the + SQL button appears.
- Click + SQL to add a SQL block.
- If you want to query NRDB data, select the account from the account selector. Other data connectors are available at the organization level and don't require account selection.
- Write your SQL query using the table reference format:
connection_name.schema.table - Click Run. The chart renders based on your query results.
- Click Save.
For further guidance, refer to the Notebooks documentation.
Query in custom dashboards
You can add SQL-based charts to your custom dashboards:
- Go to one.newrelic.com > Dashboards.
- Create a new dashboard or open an existing one.
- Click + Add widget and select a chart type.
- In the query editor, select Lens data (SQL) as the query language.
- If you want to query NRDB data, select the account from the account selector. Other data connectors are available at the organization level and don't require account selection.
- Write your SQL query using the table reference format:
connection_name.schema.table - Click Run. The chart renders based on your query results.
- Click Add to dashboard. For further guidance, refer to the custom dashboards documentation.
Important
SQL-based charts are only supported in private dashboards. Public dashboards don't support SQL queries.
SQL syntax
Lens uses ANSI SQL to query data sources, so you don't need to learn database-specific query languages.
Table reference format
When writing queries in Lens, reference tables using the format:
connection_name.schema.tableFor example:
telemetry.Transaction- Query the Transaction table from the telemetry (NRDB) connectorsnowflake.sales.orders- Query the orders table from a Snowflake connector named "snowflake" in the "sales" schemagsheets.default.employees- Query a Google Sheets connector named "gsheets"
Supported SQL statements
Lens supports standard ANSI SQL statements including:
SELECT- Query data from one or more tablesJOIN- Combine data from multiple tables (including cross-database joins)WHERE- Filter resultsGROUP BY- Aggregate dataORDER BY- Sort resultsLIMIT- Restrict the number of returned rowsWITH(CTEs) - Define common table expressions for complex queries
Performance tips
- Use filters early: Apply
WHEREclauses to reduce the amount of data processed. - Limit results: Use
LIMITto restrict returned rows when exploring data. - Consider materialized views: For frequently-run complex queries, create a materialized view.
- Optimize joins: When joining large tables, filter data before the join when possible.
Query syntax differences from NRQL and examples
Lens uses ANSI SQL instead of NRQL. The following examples show key differences and common query patterns.