Reference
Query editor
Look up what SQL the query editor accepts, how to name things, its limits, and what its common error messages mean.
The query editor is where you ask your data a question in SQL and save the answer. You can run a query for your locations and read the result in a table. You can save it as a measure or as a calculated table. A calculated table is a saved query that you can query like any other table. This page is for people who write SQL. To learn what measures, filters and group by are, read Measures.
Who can use it
To open the editor, choose Platform → Query editor in the sidebar. An admin sets the Query editor permission for each role: No access, Can view, or Can edit.
| Permission | What you can do |
|---|---|
| Can view | Open the editor. Run queries, and use the measures and calculated tables that are shared with you and your own private ones. What a query can read follows your data permissions. |
| Can edit | Create measures and calculated tables, and change the ones shared with you as Can edit. |
The owner of an item shares and archives it without Can edit. Organization owners and admins have both permissions. To see how roles combine, read Users and roles.
The SQL it accepts
The editor reads your text and decides what it is.
| Your text | The editor reads it as |
|---|---|
One value with no FROM and no GROUP BY, such as [Net sales] | A measure |
SELECT with measures or table.column, and no FROM | A measure query |
Any text with FROM | Plain SQL |
A measure query with a GROUP BY, a HAVING or a window item returns rows, so you save it as a calculated table. Every kind accepts only a SELECT. The editor refuses INSERT, UPDATE, DELETE and DROP, more than one statement, SELECT INTO, and WITH RECURSIVE.
| Clause | What it does | Note |
|---|---|---|
SELECT | Chooses the values you get. | A measure is one value, such as SUM over table.column. A measure query takes measures in square brackets, expressions and AS aliases. Plain SQL takes any columns and expressions, with a measure in the last SELECT only. |
FROM, JOIN | Chooses the tables to read. | Plain SQL only. Text with FROM is always plain SQL. |
WITH | Names a step of the query. | Plain SQL only, but not WITH RECURSIVE. A measure query refuses it. |
WHERE | Filters rows. | A measure has one WHERE, with no aggregate, OVER, subquery or measure. In a measure query it filters every measure. |
GROUP BY | Splits the result into rows per group. | A measure query takes table.column, or an expression over the columns of one table. Plain SQL with a measure takes only table.column on real table names, with no aliases or column numbers. |
HAVING | Filters the grouped rows. | Not used in a measure. Example: [Net sales] > 0. |
WINDOW, OVER | Calculates over related rows. | A measure refuses OVER. A measure query needs a GROUP BY to use OVER. |
ORDER BY | Sorts the result. | In a measure query, use the names of the result columns. |
LIMIT | Cuts the number of rows. | In a measure query, a positive whole number up to 10,000. |
OFFSET, QUALIFY | Skips rows, or filters on a window result. | Plain SQL accepts OFFSET. A measure query refuses both. Plain SQL does not support QUALIFY, and the editor reports a syntax error. |
UNION, INTERSECT, EXCEPT | Joins results. | Plain SQL only, and not with a measure in square brackets. |
| Subquery | A query inside a query. | Plain SQL only. A measure and a measure query refuse it. |
A measure has no alias, no commas outside parentheses, and no second WHERE. It cannot use COUNT(*). Name the column you count, as COUNT(dim_date.Date). In plain SQL, a FROM and a WHERE shape the rows of that query. They never change a measure.
How to name things
| What | How you write it |
|---|---|
| A measure | In square brackets, as [Net sales]. A measure is never written in a FROM. |
| A table | By its own name, as fact_sales_line, with no catalog or schema in front. |
| A calculated table | After FROM, with backticks around its name, as `Net sales per day`. |
| A column | With its table, as fact_sales_line.TotalExclVat, in a measure or a measure query. |
Names are not case sensitive. A measure and a calculated table share one set of names.
Rules for the name of a measure or calculated table:
- Use letters of any language, digits, spaces, and these signs:
.-&%(). - Start with a letter or a digit.
- Do not start or end with a space, and do not put two spaces in a row.
- Do not use
--. A single dash is allowed. - Do not use underscores, square brackets, backticks, quotes, semicolons or slashes.
- Use at most 256 characters.
- Choose a name that no other measure or calculated table in your organization has. This includes private items of colleagues that you cannot see. Archived items do not count.
Some names are reserved. You cannot use the name of a standard measure or standard calculated table, such as Net sales. You cannot use CustomerLocations, or a name that starts with Standard and a space. A calculated table also cannot have the name of a table in Tables.
A folder is a path with a slash between the folders, as Sales/Drinks. Each folder name uses letters of any language, digits, spaces, and . - & % ( ). It starts with a letter or a digit, and has no space at the start or end and no two spaces in a row. A path cannot have an empty folder, such as Sales//Drinks, and has at most 300 characters.
Functions
The editor has functions in eight groups: aggregates, window functions, conditions, text, dates and times, math, types and JSON, and lists and maps. Only these functions can be used. The editor refuses any other function, such as read_files() or IDENTIFIER(), with the message "Function x() is not available."
Limits
| Limit | Value | What happens at the limit |
|---|---|---|
| Rows in a result | 10,000 | The result is cut. The footer of the SQL cell shows 10,000+ rows. Sorting sorts only those rows. |
LIMIT in a measure query | 10,000 | The editor refuses a larger number. |
| Time a query may take | 120 seconds | The run stops with a message. |
| Text of one query, measure or calculated table | 50,000 characters | The editor refuses to run or save it. |
| Locations selected beside Run | 10,000 | The editor refuses to run. |
| Locations on one measure or calculated table | 1,000 | The editor refuses to save. |
| Name of a measure or calculated table | 256 characters | The name field stops at 256 characters. |
| Path of a folder | 300 characters | The editor refuses the folder. |
| Description | 500 characters | The text box stops at 500 characters. |
| Items, and folders, in one move, publish or archive | 200 of each | The editor refuses the action. |
To see all of your data, make the result smaller: filter the dates in your SQL, or group the rows with an aggregate such as SUM. Saving a measure runs nothing, so a query that times out can still be saved.
Error messages
A message that starts with Query execution failed: comes from your data. The editor passes it on as it is. In plain SQL, a line number in it is a line of your own text. In a measure query, it refers to SQL the editor writes for you, so check the measure names, filters and columns you used.
| Message | What it means | Fix |
|---|---|---|
| A measure has no alias: leave out AS. | The measure takes its name from the name field. | Remove AS and the name after it. |
| Name the column you count, as COUNT(dim_date.Date), so the table is clear. | COUNT was used without a column. | Write the column to count, with its table. |
| There is no measure named '…' that you can see. | No measure has this name, or it is private or not shared with you. | Check the spelling, or ask the owner to share the measure. |
| A measure query has no WITH: it reads measures, not tables. | A query on measures cannot start with WITH. | Remove WITH. To work with tables, write a calculated table or plain SQL. |
| Only SELECT statements are allowed. | The editor only reads data. It cannot change it. | Write a SELECT statement. |
| Function …() is not available. | This function is not supported in the editor. | Check the spelling. Use a function from one of the groups above. |
| Use bare table name '…' instead of '…'. | A table is written with a prefix in front of its name. | Write only the table name. |
| […] can only be used in the final SELECT list, not in a CTE, subquery or WHERE. | A measure is only calculated in the last SELECT. | Move the measure to the last SELECT list. |
| Query timed out after 120 seconds. Filter the dates or add filters. | The query took too long. A query reads all dates unless its SQL filters them. | Filter the dates in the SQL, or add another filter. Select fewer locations beside Run. |
| LIMIT can be at most 10000. | The measure query asks for more rows than a result shows. | Use a smaller number after LIMIT. |
In each message, the words in curly brackets show a name or a number in your own message.