SQL Modes¶
Every Explore workspace runs its SQL in one of two modes. In the datastore's own mode, the query runs on the datastore, written in the datastore's SQL. In Qualytics mode, the query runs in Qualytics with Spark SQL, over the datastore's containers as Qualytics sees them. The mode is saved with the workspace, so it is still set the next time you open it.
The Mode Switch¶
The switch sits next to Run in the editor's header. It has two options:
| Option | What it shows | Tooltip |
|---|---|---|
| The datastore's engine | The datastore's logo and its connector name, such as PostgreSQL or Snowflake | Runs on <datastore>, in its own SQL |
| Qualytics | The Qualytics logo | Runs in Qualytics with Spark SQL, over this datastore's tables as Qualytics sees them. Reads computed tables and computed fields too. |
When the editor is narrow, the switch keeps the logos and hides the names.
Switching the mode does not rewrite your SQL. Write the query for the mode you pick: a query that uses functions of your database may not run in Qualytics mode, and a query that reads a computed table does not run in the datastore's mode.
To change the mode, see Switch the SQL Mode.
The Editor Hint¶
The hint on the line under the editor names what the editor expects in the current mode:
- Datastore's mode:
Any valid <connector> query, for exampleAny valid PostgreSQL query. - Qualytics mode:
Any Spark SQL query over this datastore's containers.
Autocomplete, Format, and the way names are quoted follow the same mode. See Query Editor.
Datastore SQL¶
In the datastore's mode, Explore sends the query to the datastore, which runs it in its own SQL dialect. Use any SQL your database accepts in a read-only query: its functions, its date arithmetic, its casts.
Table Names¶
A table name on its own reads from the database and schema of the workspace's datastore. The Editor context card of the editor names that location, for example Table names on their own are read from analytics.public.
Other Datastores on the Same Connection¶
A query can also read the other datastores that share the datastore's connection. Put the other datastore's location in front of the table name:
- On most engines, write the schema first:
sales.orders. - On engines that read across databases, write the database and the schema:
warehouse.sales.orders. These engines are Amazon Athena, BigQuery, Databricks, Dremio, Microsoft Fabric, Hive, MariaDB, MySQL, Presto, Amazon Redshift, Snowflake, SQL Server, Teradata, and Trino.
The +N button next to the datastore button lists these datastores and inserts their prefix for you. It lists only the datastores you can run SQL on. See Read Another Datastore.
A query reads only datastores on the same connection. A name that does not belong to any datastore of the connection is refused.
To run the query, you need the Author or Editor team permission on every datastore it reads. See Permissions.
When several datastores point at the same database and schema, the query reads that location through one of them: the workspace's own datastore when it matches, otherwise one of the others. The Read from chip on the results bar shows which datastores a run read. See Results.
Synced Tables Only¶
A query reads only tables that Qualytics has synced for the datastore, in both modes. A table that exists in the database but was never synced is refused, and so are the database's system and catalog views. Engine placeholder tables such as DUAL are allowed. To query a table that is missing, sync the datastore first. See Sync.
A reference dataset installed on an enrichment datastore is read by its table name in Qualytics, such as reference_7_countries, in both modes. Qualytics reads the rows of the release in use.
Computed Assets Need Qualytics Mode¶
Computed tables and computed files exist only in Qualytics, so the datastore cannot read them. When your SQL names one in the datastore's mode, a notice appears under the editor:
- One asset:
<name> is a computed table, which only Qualytics reads.(orcomputed file) - Several:
<names> are computed assets, which only Qualytics reads.
The notice has a Run in Qualytics button that switches the workspace to Qualytics mode. The SQL stays as it is.
Qualytics Mode¶
In Qualytics mode, Qualytics runs the query with Spark SQL over the containers of the workspace's datastore. Qualytics reads each container the query names in full before it runs the query, so a query over large containers can take longer here than the same query on the datastore.
What It Reads¶
| Asset | Readable in Qualytics mode |
|---|---|
| Tables, views, and files of this datastore | |
| Computed tables | |
| Computed files | |
| Computed fields | |
| Computed joins | |
| Other datastores, even on the same connection |
The +N button is empty in this mode, because the query reads its own datastore only.
Naming Containers¶
Name each container by its name alone, with no schema or database in front of it. When the name is not a plain identifier, such as a file pattern with a slash or a dot, quote it with backticks:
Container names are matched without regard to letter case. Before the query runs, Qualytics writes each container name as the container spells it, together with any column prefix that repeats the name, such as orders.id. So FROM orders reads a container named ORDERS. Aliases are left as you wrote them. Column names are not changed: Spark SQL matches them by letter case, so write each column as the container spells it.
Limits¶
- A query reads at most 10 containers.
- Only Spark SQL's built-in functions run. The reflection functions (
reflect,java_method,try_reflect) and the Avro, Protobuf, and XML functions (such asfrom_avro,from_protobuf,from_xml) are refused. - Table functions are limited to the ones that generate rows, such as
range,explode,explode_outer,inline,inline_outer,json_tuple,posexplode,posexplode_outer, andstack. - Save as computed table is disabled in this mode, because a computed table runs on the datastore in its own SQL.
File Datastores¶
A file datastore has no database engine to run SQL on, so its workspaces run in Qualytics mode only. The switch shows the Qualytics option alone and cannot be changed. Its tooltip reads Runs in Qualytics.
File containers are named by their file patterns, so quote them with backticks.
Save as computed table does not appear for a file datastore. In its place, Save as computed file saves the Spark SQL as a computed file. A computed file reads one file container, so the query must name exactly one container of the datastore. A query that names several is refused with A computed file reads one file, and its query reads <count>: <names>. See Computed Files.
Read-Only Rules¶
Explore only reads data. Qualytics checks each query when you run it and refuses anything that could change data, reach outside the datastores you can query, or show masked values that it cannot trace. A refused query does not run, and the results card shows the reason. Refused queries are not recorded in History.
A few problems are caught before you run. In that case Run is disabled, its tooltip gives the reason, and the results card shows Running is not available with the same reason.
SQL the Database Reads Differently¶
Some SQL reads one way to the check and another way to the database. Qualytics refuses it before the query is read at all, because what the database would run cannot be checked:
- A name written with Unicode escapes,
U&"...", on PostgreSQL, Redshift, and Teradata. - A name written in hex,
'...'XN, on Teradata. - A
{# ... #}comment, which MySQL runs. - A comment inside another comment, which databases end at different places.
- A MySQL or MariaDB executable comment,
/*! ... */.
Refusal Messages¶
| Group | Situation | Message |
|---|---|---|
| Read only | A syntax error | The query could not be read near line <line>, column <column>. Check its syntax, then run it again. |
| Read only | Parentheses or subqueries nested too deeply to check (about 50 levels) | The query is nested too deeply to be checked. Write it with fewer levels. |
| Read only | More than one statement in what runs | Run one query at a time. |
| Read only | A statement that writes, such as INSERT, UPDATE, DELETE, SELECT INTO, FOR UPDATE, or DDL |
Only a read-only query can run here: it cannot create, change or delete data. |
| Read only | A MySQL or MariaDB executable comment | A /*! ... */ comment cannot run here: the database runs what it holds, which cannot be checked. Write the SQL without it. |
| Read only | A name written U&"..." |
A name written U&"..." cannot run here: the database decodes the name it holds, which cannot be checked. Write the name without U&. |
| Read only | A name written in hex | A name written in hex ('...'XN) cannot run here: the database decodes the name it holds, which cannot be checked. Write the name itself. |
| Read only | A {# ... #} comment |
A {# ... #} comment cannot run here: the database runs what it holds. Write the SQL without it. |
| Read only | A comment inside a comment | A comment inside a comment cannot run here: databases disagree on where it ends, so what follows cannot be checked. Write the SQL without it. |
| Read only | TABLE name as a query |
TABLE name cannot be checked here. Write it as SELECT * FROM name. |
| Read only | TABLE name inside a WITH clause |
A WITH clause must hold a query. Write TABLE name as SELECT * FROM name. |
| Access | No Author or Editor team permission on a datastore the query reads | Running SQL needs Editor or Author permission on <datastore> |
| Access | A name that belongs to no datastore of the connection you can query | <name> is not in a datastore you can query here. Name a table of one of the connection's datastores you have access to. |
| Access | A table Qualytics has not synced, or a system view | <table> is not a table Qualytics has synced in <datastore>. Query the datastore's synced tables, or sync it to add a new one. |
| Access | A schema written where a table belongs | <name> is a schema, not a table. Name one of its tables after it. |
| Access | A database and a table with the schema left out, such as warehouse..orders |
<database>..<table> leaves out the schema. Name it between the database and the table. |
| Functions | A function that runs SQL from text, reads files, other servers, other sessions, settings, secrets, or object definitions, or waits or takes locks, such as dblink, pg_read_file, pg_sleep, sleep, openrowset, load_file, or IDENTIFIER() |
<function>() can't be read here. Queries read the tables of datastores you have access to. |
| Functions | A function called through INFORMATION_SCHEMA, a Snowflake SYSTEM$ function other than SYSTEM$TYPEOF, or a call into an Oracle DBMS_ or UTL_ package other than DBMS_LOB and DBMS_RANDOM |
<function>() can't be read here. Queries read the tables of datastores you have access to. |
| Functions | A function in FROM or JOIN, or after TABLE, LATERAL, or APPLY, that does more than turn its arguments into rows. Row functions such as generate_series, UNNEST, explode, or jsonb_array_elements, and subqueries, are allowed there. |
<function>() can't be read here. Queries read the tables of datastores you have access to. |
| Functions | Hive's TRANSFORM ... USING |
TRANSFORM ... USING can't be read here. Queries read the tables of datastores you have access to. |
| Qualytics mode | No container named | Name a container of <datastore> to read. Spark SQL reads the datastore's containers |
| Qualytics mode | More than 10 containers | Spark SQL reads at most 10 containers at once |
| Qualytics mode | A name that is not one of the datastore's containers | <name> is not a container of <datastore>. Spark SQL reads the datastore's containers by name |
| Qualytics mode | A name with a prefix in front of it | <prefix.name> is not a container of <datastore>. Spark SQL reads this datastore's containers, each by its name alone. Quote a name like a/b.csv with backticks. |
| Qualytics mode | A container name written in quotes instead of backticks | Spark SQL reads '<name>' as text, not as a container. Name it in backticks: `<name>` |
| Qualytics mode | A computed join | <name> is a computed join, which Spark SQL cannot read here |
| Masking | PIVOT or UNPIVOT over a table with masked fields |
PIVOT and UNPIVOT cannot run on a table with masked fields: their masked values could not be traced to the result columns that show them. |
| Masking | MATCH_RECOGNIZE over a table with masked fields |
MATCH_RECOGNIZE cannot run on a table with masked fields: their masked values could not be traced to the result columns that show them. |
| Masking | UNION BY NAME or CORRESPONDING |
BY NAME and CORRESPONDING cannot run on a table with masked fields: their masked values could not be traced to the result columns that show them. |
| Masking | FOR JSON or FOR XML |
FOR JSON and FOR XML cannot run on a table with masked fields: the one column they return could not be masked. |
| Masking | Columns renamed in the table's alias, such as FROM orders AS t(a, b) |
<table> has masked fields, so its columns cannot be renamed after its alias. Rename them with AS in the SELECT instead. |
| Masking | A value read by position or from a variable, such as $2, @ssn, or @v := ssn |
A value read by position or from a variable ($2, @name) cannot run on a table with masked fields. Name the column instead. |
| Masking | A column that stands for another one: $IDENTITY, $ROWGUID, IDENTITYCOL, or ROWGUIDCOL on SQL Server, _rowid on MySQL and MariaDB |
<name> cannot run on a table with masked fields: the column it stands for could not be traced. Name the column instead. |
| Masking | PRIOR or BINARY written bare before a column, or another bare word before a masked field's name, which some engines read as an operator on the column |
<word> <name> could not be traced to the fields it shows. Name the column with AS. |
| Masking | * with EXCLUDE, ILIKE, REPLACE, or RENAME over a table with masked fields |
A * with EXCLUDE, ILIKE, REPLACE or RENAME cannot run on a table with masked fields. Name the columns instead. |
| Masking | A * that opens a value into columns, such as (o).*, (jsonb_each(...)).*, STRUCT(...).*, or s.* over a struct column |
A * that opens a value into columns cannot run on a table with masked fields. Name each column instead. |
| Masking | A * the check cannot open into its columns, such as SELECT * over a subquery on Snowflake and Oracle |
This query reads masked fields through a * that could not be traced to its result columns. Select the columns by name. |
| Masking | A row function that reads a field its table masks, such as UNNEST(ARRAY[ssn]) |
<function>() can't turn a masked field into rows here: its values couldn't stay masked. Leave the masked field out of it. |
| Masking | A VALUES list holding a masked field, with no column names after its alias |
VALUES cannot hold a masked field unless the alias after it names its columns, as in (VALUES (ssn)) AS v(x). |
| Masking | A subquery without FROM that reads a masked field of the query around it, such as (SELECT ssn) |
A subquery without FROM reads a column of the query around it that could not be traced to the fields it shows. Give the subquery its own FROM. |
| Masking | A function that returns several columns and reads a masked field | A function that returns several columns cannot read a masked field here, since its columns could not be masked one by one. Select from it in a subquery and name each column. |
| Masking | An expression over a masked field with no column name, such as ssn::int, +ssn, ssn->'a', or ssn[1]. On Snowflake and Oracle, any expression over a masked field without AS. |
A result column computed from a masked field needs a name, so its values can be masked. Name it with AS. |
| Masking | Two columns with the same name in one SELECT, anywhere in a query that reads masked fields |
Two result columns are named <name>. Give each its own name with AS, so masked values can be found. |
| Masking | Any other shape that cannot be traced to its masked fields | This query reads masked fields in a way Qualytics cannot trace to its result columns, so their values could not be masked. Select the columns by name. |
| Masking | An enrichment table whose source container is no longer known | <datastore> holds a table Qualytics cannot tie to the source container it was written from, so it cannot tell which of its fields to mask. Link the source datastore to it again to query it with SQL |
The masking rules apply only when the query reads a table with masked fields. A masked field that the query only uses to filter, join, or count is allowed: the result does not show its values.
A query that passes the checks can still fail when it runs. When a column the query names for a masked field, such as ssn or upper(ssn) AS shown, comes back from the database under another name, the run fails before any row is shown, with The result has no column <name> to mask, so its rows were not returned. Give the column a short, plain name with AS and run the query again. This happens, for example, with a name that holds a dot, such as AS "a.b". A short, plain name with AS avoids it. To learn how masked values appear in results, see Results and Field Masking.
To find which masked fields a result column shows, Qualytics follows each column to the table, subquery, or common table expression it reads from, by the alias of its own query. A query can reuse an alias in different subqueries, or name a common table expression after the table it reads, and each column is still traced to the right source.
Masking is a safeguard, not a guarantee
These checks are written to keep masked values out of results, and Qualytics refuses a query whenever it cannot trace one. They work from the SQL as written, so they cannot cover every way each database can read a value. Keep sensitive data protected in the database too, by limiting what the datastore's connection can read.
In Qualytics mode, Spark SQL also refuses statements that write and functions outside its allowed list, with its own message.
See Also¶
-
Query Editor
The editor's controls: the datastore, the SQL badge, autocomplete, running a statement or a selection, formatting, and saving a computed table or file.
-
Results
The results grid, row counts, query details, cell values, masked values, and downloads.
-
Charts
Bar, line, and scatter charts of the rows loaded so far, charts proposed by AgentQ, and their PNG and PDF downloads.
-
History
The runs of each workspace, and the History page where Admins review every query run.
-
Assets
The datastores, tables, and fields you can drag into your SQL, and why some of them stay locked.
-
Explore Assistant
The AgentQ chat beside each workspace that proposes queries and charts, and helps fix failed queries.
-
Datastore and Container Tabs
The Explore tab of a datastore, and the Explore tab of a table or file with its fields, filter, and custom columns.
-
Examples
Questions people answer with Explore, and the queries and settings that answer them.
-
Best Practices
Habits that keep queries fast, results trustworthy, and masked data protected.
-
Permissions
The user roles and team permissions behind running SQL, revealing masked values, and reviewing history.
-
How Explore Works
What a run is, how rows load as you scroll, how a run ends, and the limits that apply to every result.
-
Workspaces
The saved, private places that hold each query, its datastore, and its last result.