TelemetryDeck speaks SQL now
TelemetryDeck now runs queries written in SQL, so you can use existing database experience to query your analytics data. SQL coexists peacefully with the TelemetryDeck Query Language TQL.

For those of us who occasionally work with databases, SQL is a standardized way to run queries against almost any database.
TelemetryDeck has its own Query Language, TQL, whose JSON-based format is a bit cumbersome though, especially for quick, throw-away queries that feel like they’re right at the fingertips of people experienced with SQL.
Which is why I’m super happy to say that TelemetryDeck now supports running queries in both SQL and TQL. The UI only shows query results as tables, and will evolve a lot over the coming weeks, but the foundations are here, and we took some time to make them strong!
The first place where you can use an SQL query today is Notebooks. Just as you can type ```tql into a a Notebook to start working on a TQL query, you can now also start a block with ```sql to enter an SQL query of your choice and we’ll display the results in a really good looking table if I may say so myself!

If you create a new Notebook, it will include an example SQL query by default.
We’ve also added a “Convert to TQL” button for those who want to quickly start with SQL but want to switch to a more structured editor later. This is also a way to display the data as a chart.
The new v4 Query API supports both SQL and TQL queries. See the API docs for more information and examples.
Use {{events}} as table name
In SQL, you’re always selecting FROM something. In a relational database, this would be a table name, but TelemetryDeck’s data format has no tables. Instead, use either the {{events}} shortcut, or your namespace.
{{events}} contains your analytics data, automatically filtered by App ID, Test Mode, the date picker’s date range, and any global filters you’ve set:
SELECT * FROM {{events}} LIMIT 100If instead you want to bypass all these automatic filters, or you’re directly querying the API, use your organization’s namespace as a table name and set your filters and intervals yourself:
SELECT * FROM "<namespace>"
WHERE "__time" >= CURRENT_TIMESTAMP - INTERVAL '1' MONTH
AND "isTestMode"="false"
LIMIT 100Note that {{events}} won’t work in queries to the API.
It’s full-assed SQL

Your queries are running in a complete SQL engine that supports pivots, subqueries, joins, group by, unions, window functions and more.
All of your event properties are available as columns. This means our default event parameters are there, as is every property you’ve attached to an event in TelemetryDeck. If the property is not there for an event, it will be of value NULL.
You’re directly accessing the TelemetryDeck namespace, which means that you’ll also need to account for its eccentricities. The most important of these is that we roll up events that are the same in every way and arrived within the same hour. Two events become one row with a count value of 2. This is why you should always use SUM("count") when counting events, never COUNT(*).
Just like all queries in TelemetryDeck, SQL queries are read-only. You can’t actually update or drop your data because the way TelemetryDeck stores time series analytics events doesn’t support that.
TQL is here to stay

While SQL is easy to write and read as a human, TQL is a better way to structure queries in a machine readable way. It serves as a domain specific language to specify exactly what data to query, and how, and with which properties and filters, making it the ideal language to power our user interface.
TQL queries also run faster in a lot of situations, because you can define more clearly how and in what order to aggregate data. For example, our “topN” queries are incredibly more optimized and faster, so we use them over the more versatile “groupBy” queries wherever possible. SQL can’t always make that distinction, so some SQL queries will run slower than some TQL queries.
Finally, TQL also allows us to extend the language. We have custom TQL queries for A/B Testing Experiments, Funnels, Retention Queries and more, that allow us to abstract away a lot of complexity that we only need to define once. Which is why I love that we’re supporting SQL and TQL equally.
Starting today, we suggest SQL as the default way to start if you’re writing queries by hand. You can always convert them to TQL later for fine-tuning, but in the meantime you’ll be writing way fewer curly braces.
Neither SQL nor TQL queries can read data from other organizations

Give a computer a random SQL query as a string, and it won’t be able to fully determine what it’ll do before executing it. There are many ways to construct a query that passes a given test from a program, but does something malicious.
Previously, our access controls were on the API level: every query passing through our API to the data servers would get an additional processing step that made sure the dataSource of the query matched the caller’s namespace. We could do that because a TQL query is a fully parseable object and more restricted object, and computers can understand it fully.
With SQL, that was no longer enough. First we thought we could run the query through the actual engine that interprets it and ask for just a plan. This way we’d get machine-readable data about what the query really does and what data it asks access to. However, asking a data server twice for something increases time and server load.
So after some experiments, we decided to rework the whole sequence: Instead of multiple round-trips to the data server, we’ve moved access control completely into the data servers that actually execute the query.
Each query gets tagged with its user and their organization namespaces. The data servers themselves make sure that they only access those namespaces during execution. This happens for both SQL and TQL queries, and has been live for a few weeks, improving our data security.

Next Up: Insights and Charts
Using SQL to show a table in a Notebook is nice, but what about Insights, and what about actually driving a chart? The next work item in that area are “Insight Specs”.
An Insight Spec holds one or multiple queries, and information about how to display their results: as a table? As a bar chart? As a pie? It also allows us to define the design and presentation of charts in a new way that is more flexible.
Once that format works well, we’ll want to use it in Dashboards, Insights, and Notebooks. But we’ll need to work on it some more. You can see a preview of our work and some examples of what an Insight Spec can do by navigating to Explore → Spec Library in the TelemetryDeck Dashboard.
Thank you
Some of us occasionally work with some databases, but thanks to TelemetryDeck’s fantastic customers, I get to work full time on Time Series Databases, really complex data, and fascinating user interfaces.
I love that this is my job: going deep into the query execution layer, and then resurfacing and making sure the charts look gorgeous and fine. Thank you so much to all of our customers for making this possible 🩵
