DuckDB UI中,即时SQL查询,边输入边出结果。
Instant SQL for results as you type in DuckDB UI

原始链接: https://motherduck.com/blog/introducing-instant-sql/

MotherDuck 推出了 Instant SQL,这是一种革命性的编写 SQL 的方式,它可以在您键入时提供实时结果集预览,从而消除了传统的编写-运行-等待周期。Instant SQL 专为 MotherDuck 和 DuckDB 本地 UI 而构建,它利用 DuckDB 的速度和复杂的缓存系统来提供零延迟反馈,从而加快查询构建和调试速度。 其主要功能包括:实时可视化 CTE(公共表表达式),允许用户实时检查和编辑 CTE;以及能够分解复杂的列表达式以简化调试。它支持查询各种数据源,包括 MotherDuck 中的表、S3 Parquet 文件和 Postgres 数据库。此外,MotherDuck 用户现在可以使用内联 AI 提示编辑功能,并立即预览 AI 建议的结果。Instant SQL 结合了快速的 SQL 引擎、易于访问的解析器、精确的光标到 AST(抽象语法树)的映射以及智能缓存。

Hacker News 的讨论围绕着 DuckDB UI 新的“即时 SQL”功能展开,该功能允许用户在输入时查看查询结果。用户赞扬了该功能的独创性和在调试复杂查询(尤其是 CTE)方面的潜力。讨论包括潜在的改进,例如可调整的更新频率和空间可视化支持。一个反复出现的主题是希望在 SQL 中使用类似于 Kusto 或 LINQ 的管道语法,以提高可读性和自动完成能力。提到了 PRQL 和 Malloy 等替代方案。开发人员讨论了底层技术,包括使用 DuckDB 的 SQL 查询的 JSON AST 表示。讨论还涵盖了潜在的 UI 改进,例如轻松查看整个表和导出笔记本的功能。解决了关于意外 DELETE 语句的安全问题,开发人员确认该功能仅预览 SELECT 查询。用户对离线模式和 UI 的开源感到兴奋。
相关文章
  • DuckDB本地UI 2025-03-13
  • Show HN:10 年打造免费 SQL 编辑器 2024-06-05
  • (评论) 2024-08-23
  • (评论) 2025-03-13
  • DuckDB:发展路线图 2025-03-26

  • 原文

    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.

    联系我们 contact @ memedata.com