Back Original

Instant SQL for results as you type in DuckDB UI

Today, we’re releasing Instant SQL, a new way to write SQL that updates your result set as you type to expedite query building and debugging – all with zero-latency, no run button required. Instant SQL is now available in Preview in MotherDuck and the DuckDB Local UI.

Intro GIF

We built Instant SQL for a simple reason: writing SQL is still too tedious and slow. Not because of the language itself, but because the way we interact with databases hasn’t evolved much since SQL was created. Writing SQL isn’t just about syntax - It’s about making sense of your data, knowing what to ask, and figuring out how to get there. That process is iterative, and it’s hard.

"Instant SQL will save me the misery of having to try and wrangle SQL in my BI tool where iteration speed can be very slow. This lets me get the data right earlier in the process, with faster feedback than waiting for a chart to render or clearing an analytics cache." -- Mike McClannahan, CTO, DashFuel

Despite how much database engines have improved, with things like columnar storage, vectorized execution, and the creation of blazing-fast engines like DuckDB, which can scan billions of rows in seconds, the experience of building a query hasn’t kept up. We still write queries in a text editor, hit a run button, and wait to see what happens.

At MotherDuck, we've been tackling this problem from multiple angles. Last year, we released the Column Explorer, which gives you fast distributions and summary statistics for all the columns in your tables and result sets. We also released FixIt, an unreasonably effective AI fixer for SQL. MotherDuck users love these tools because they speed up data exploration and query iteration.

Instant SQL isn't just an incremental improvement to SQL tooling: It's a fundamentally new way to interact with your queries - one where you can see your changes instantly, debug naturally, and actually trust the code that your AI assistant suggests. No more waiting. No more context switching. Just flow.

Let's take a closer look at how it works.

Generate preview results as you type

Everyone knows what it feels like to start a new query from scratch. Draft, run, wait, fix, run again—an exhausting cycle that repeats hundreds of times a day.

Instant SQL gives you result set previews that update as you type. You're no longer running queries—you're exploring your data in real-time, maintaining an analytical flow state where your best thinking happens.

GIF 1

Whether your query is a simple transformation or a complex aggregation, Instant SQL will let you preview your results in real-time.

GIF 2

Inspect and edit CTEs in real-time

CTEs are easy to write, but difficult to debug. How many times a day do you comment out code to figure out what's going on in a CTE? With Instant SQL, you can now click around and instantly visualize any CTE in seconds, rather than spend hours debugging. Even better, changes you make to a CTE are immediately reflected in all dependent select nodes, giving you real-time feedback on how your modifications cascade through the query.

GIF 3

Break apart your complex column expressions

We've all been there; you write a complex column formula for an important business metric, and when you run the query, you get a result set full of NULLs. You then have to painstakingly dismantle it piece-by-piece to determine if the issue is your logic or the underlying data.

Instant SQL lets you break apart your column expressions in your result table to pinpoint exactly what's happening. Every edit you make to the query is instantly reflected in how data flows through the expression tree. This makes debugging anything from complex numeric formulas to regular expressions feel effortless.

GIF 4

Preview anything DuckDB can query - not just tables

Instant SQL works for more than just DuckDB tables; it works for massive tables in MotherDuck, parquet files in S3, Postgres tables, SQLite, MySQL, Iceberg, Delta – you name it. If DuckDB can query it, you can see a preview of it.

This is, hands down, the best way to quickly explore and model external data.

GIF 5

Fast-forward to a useful query before running it

Instant SQL gives you the freedom to test and refine your query logic without the wait. You can quickly experiment with different approaches in real-time. When you're satisfied with what you see in the preview, you can then run the query for your final, materialized results. This approach cuts hours off your SQL workflow, transforming the tedious cycle of write-run-wait into a fluid process of exploration and discovery.

GIF 6

Instantly preview AI-powered edit suggestions

All of these workflow improvements are great for humans, but they're even better when you throw AI features into the mix. Today, we're also releasing a new inline prompt editing feature for MotherDuck users. You can now select a bit of text, hit cmd+k (or ctrl+k for Windows and Linux users), write an instruction in plain language, and get an AI suggestion.

Instant SQL makes this inline edit feature work magically. When you get a suggestion, you immediately see the suggestion applied to the result set. No more flipping a coin and accepting a suggestion that might ruin your hard work.

GIF 7

Why hasn't anyone done this before?

As soon as we had a viable prototype of Instant SQL, we began to ask ourselves: why hasn't anyone done something like this before? It seems obvious in hindsight. It turns out that you need a unique set of requirements to make Instant SQL work.

A way to drastically reduce the latency in running a query

Even if you made your database return results in milliseconds, it won’t be much help if you’re sending your queries to us-east-1. DuckDB’s local-first design, along with principled performance optimizations and friendly SQL, made it possible to use your computer to parse queries, cache dependencies, and rewrite & run them. Combined with MotherDuck’s dual execution architecture, you can effortlessly preview and query massive amounts of data with low latency.

A way to rewrite queries

Making Instant SQL requires more than just a performant architecture. Even if DuckDB is fast, real-world ad hoc queries may still take longer 100ms to return a result. And of of course, DuckDB can also query remote data sources. We need a way to locally cache samples of certain table references and rewrite our queries to point to those.

A few years ago, DuckDB hid a piece of magic in the JSON extension: a way to get an abstract syntax tree (or AST) from any SELECT statement via a SQL scalar function. This means any toolmaker can build parser-powered features using this important part of DuckDB's database internals - no need to write your own SQL parser from scratch.

A caching system that accurately models your query

Of course, showing previews as you type requires more than just knowing where you are in the query. We've implemented several sophisticated local caching strategies to ensure results appear instantly. Think of it as a system that anticipates what you might want to see and prepares it ahead of time. The details of these caching techniques are interesting enough to deserve their own blog post. But suffice it to say, once the cache is warm, the results materialize before you can even lift your fingers from the keyboard.

Without this perfect storm of technical capabilities – a fast local SQL engine, parser accessibility, precise cursor-to-AST mapping, and intelligent caching – Instant SQL simply couldn't exist.

A way to preview any SELECT node in a query

Getting the AST is a big step forward, but we still need a way to take your cursor position in the editor and map it to a path through this AST. Otherwise, we can’t know which part of the query you're interested in previewing. So we built some simple tools that pair DuckDB’s parser with its tokenizer to enrich the parse tree, which we then use to pinpoint the start and end of all nodes, clauses, and select statements. This cursor-to-AST mapping enables us to show you a preview of exactly the SELECT statement you're working on, no matter where it appears in a complex query.

Try Instant SQL

Instant SQL is now available in Preview in MotherDuck and the DuckDB Local UI. Give it a try to experience firsthand how fast SQL flies when real-time query results are at your fingertips as you type. Our new, prompt-based Edit feature is also available to MotherDuck users.

We’d love to hear more about how you’re using Instant SQL, and we look forward to hearing your stories and feedback on social media and in Slack.

PS: We’re hiring!

At MotherDuck, we’re building a future where analytics work for everyone - from new UI features like Instant SQL to the platforms and databases that power them. If you’re passionate about building complex, data-intensive interfaces, we’re hiring, and we’d love to have you join the flock to help us make these features even more magical.

CONTENT

  1. Inspect and edit CTEs in real-time
  2. Break apart your complex column expressions

Start using MotherDuck now!