<?xml version="1.0" encoding="utf-8"?>

<feed xmlns="http://www.w3.org/2005/Atom" >
  <generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator>
  <link href="https://duckdb.org/feed.xml" rel="self" type="application/atom+xml" />
  <link href="https://duckdb.org/" rel="alternate" type="text/html" />
  <updated>2026-12-06T12:39:35+00:00</updated>
  <id>https://duckdb.org/feed.xml</id>

  
  
  

  
    <title type="html">DuckDB</title>
  

  
    <subtitle>DuckDB is an in-process SQL database management system focused on analytical query processing. It is designed to be easy to install and easy to use. DuckDB has no external dependencies. DuckDB has bindings for C/C++, Python, R, Java, Node.js, Go and other languages.</subtitle>
  

  

  

  
    <author>
        <name>GitHub User</name>
      
        <email>your-email@domain.com</email>
      
      
    </author>
  

  
  
  
  
  
  
  
  
    <entry>
      

      <title type="html">How Atlan Moved Its Data Platform from Spark and StarRocks to DuckDB on S3</title>
      <link href="https://duckdb.org/2026/12/01/atlan-metadata-platform-duckdb.html" rel="alternate" type="text/html" title="How Atlan Moved Its Data Platform from Spark and StarRocks to DuckDB on S3" />
      <published>2026-12-01T00:00:00+00:00</published>
      <updated>2026-12-01T00:00:00+00:00</updated>
      <id>https://duckdb.org/2026/12/01/atlan-metadata-platform-duckdb</id>
      
      
        <content type="html" xml:base="https://duckdb.org/2026/12/01/atlan-metadata-platform-duckdb.html"><![CDATA[<p><a href="https://atlan.com/">Atlan</a> now runs its entire data platform on DuckDB and object storage, handling both analytical and operational workloads. DuckDB runs in-process on Parquet files and Apache Iceberg tables in Amazon S3, a DuckDB service on ephemeral compute has replaced StarRocks at about 40% lower cost, and Atlan's new AI registry is built on the same foundation. Several of Atlan's patches are in <a href="/2026/10/21/announcing-duckdb-200.html">DuckDB 2.0</a>.</p>

<figure class="quote"><blockquote class="quote-large">
  <p>Quote</p>

  <p>It almost seemed too good to be true: in-process, zero external dependencies, lightweight, and super fast.</p>

  
</blockquote><figcaption class="quote-author"><img src="/images/blog/authors/mustafa_khan_atlan.jpg" alt="" class="avatar" loading="lazy">Mustafa Khan, senior software engineer, Atlan</figcaption></figure>

<h2 id="what-atlan-does">What Atlan Does</h2>

<p>Atlan is the context layer for AI. It began as a data catalog and lineage tool that pulls metadata from every warehouse, database, and BI tool an organization runs, so data teams can see where a number came from, who owns it, and whether it can be trusted. That problem only grows with the organization, which is why Atlan's customer base skews toward large enterprises, including Fortune 100 companies.</p>

<p>The same question now comes from AI agents. When an agent answers "what was our churn rate last quarter?", a 200 OK response from the API does not mean the answer is correct because the agent may not know which source it used. Atlan gives agents governed, verifiable context, so that an agent's output can be traced and checked in the same way as a dashboard. Agents also read that context far more often than people do, and write back what they learn, which puts much more load on the platform underneath.</p>

<h2 id="processing-metadata-on-spark">Processing Metadata on Spark</h2>

<p>Atlan ingests metadata about every data asset in the systems it connects to: technical metadata, usage data, and lineage. Until 2024 all of that processing ran on <a href="https://spark.apache.org/">Apache Spark</a> with Delta Lake. One of the heaviest parts was building lineage, for which Atlan ingests query history from its customers’ warehouses, billions of rows of it, and works out which tables feed which reports.</p>

<p>Spark was not scaling with the workload. Costs grew with every customer, and the pipelines regularly failed with out-of-memory errors that engineers had to investigate. The workload was batch analytics over files in object storage, and running a distributed cluster for it added cost and operational work the team wanted to avoid.</p>

<h2 id="moving-to-duckdb">Moving to DuckDB</h2>

<p>Atlan had been following DuckDB since the 0.2 releases. For a team that wanted to process files in S3 without running a cluster, it fit well: it runs inside the Python process the pipeline already uses, it has no external dependencies, and it reads Parquet from object storage directly. <strong>"It almost seemed too good to be true,"</strong> says <a href="https://www.linkedin.com/in/mustafahasankhan">Mustafa Khan</a>, a senior software engineer who has been at Atlan for four years and led the migration together with an architect.</p>

<p>The early builds crashed with segmentation faults, and the team filed a series of issues in 2024, some of which led to improvements in DuckDB's Parquet reader. The approach still suited Atlan: start with a small component running inside the existing process, and add infrastructure only when a workload needs it.</p>

<h2 id="how-the-pipelines-run-today">How the Pipelines Run Today</h2>

<p>Atlan's metadata pipelines now run DuckDB in-process, inside Python workers on Kubernetes pods and <a href="https://temporal.io/">Temporal</a> workflows. Each worker reads the Parquet files it needs from S3, runs the lineage and processing queries locally, and writes results back to object storage. Atlan does not need to size a cluster or keep a coordinator running, and there is no second system to deploy on a customer's infrastructure. That matters because many of its enterprise customers want both the platform and the data to stay in their own cloud account, and with DuckDB the data stays there in open formats, Parquet and Iceberg, that other engines can read as well.</p>

<p>Data volumes are the same as before. Across its customer base Atlan processes hundreds of millions of rows on a typical day and billions on the busiest days. According to Mustafa, the pipelines are faster than the Spark versions and cost far less to run.</p>

<h2 id="replacing-starrocks-and-clickhouse">Replacing StarRocks and ClickHouse</h2>

<p>After the Spark migration, DuckDB became Atlan's default choice for any workload that reads or writes S3, and the company has since replaced other systems with it.</p>

<p>The most recent was <a href="https://www.starrocks.io/">StarRocks</a>. With DuckDB already running the pipelines, Atlan wanted a single engine for processing and serving, and an isolated instance per tenant rather than a shared cluster. In October it shut down its StarRocks clusters. It now runs an in-house service based on DuckDB on ephemeral compute that reads and writes object storage directly. Costs fell by about 40%.</p>

<p>Atlan is also replacing <a href="https://clickhouse.com/">ClickHouse</a> for trace storage with a design that writes from DuckDB directly to object storage, because it is faster on Atlan's workload and easier to deploy. The new AI registry, built on AWS, uses DuckDB to read and write S3, with <a href="https://iceberg.apache.org/">Apache Iceberg</a> tables and an Iceberg REST catalog on top. Atlan can still be deployed on any cloud, but its data platform now consists of DuckDB and object storage, handling both analytical and operational workloads.</p>

<h2 id="contributing-to-duckdb-20">Contributing to DuckDB 2.0</h2>

<p>Atlan is already running the <a href="/2026/10/21/announcing-duckdb-200.html">DuckDB 2.0</a> alpha internally and plans to ship its next data-platform release on it, having seen no regressions compared with the 1.x release it used before.</p>

<p>Mustafa has had several pull requests merged for 2.0:</p>

<ul>
  <li>aggregates whose state holds strings or lists now spill to disk instead of failing with an out-of-memory error (<a href="https://github.com/duckdb/duckdb/pull/24499">#24499</a>)</li>
  <li>an opt-in setting lets the external file cache write evicted blocks of remote files to the temporary directory, so that a later query reads them back from local disk rather than fetching them from S3 again (<a href="https://github.com/duckdb/duckdb/pull/24062">#24062</a>)</li>
  <li>JSON functions for in-place edits: <code class="language-plaintext highlighter-rouge">json_set</code>, <code class="language-plaintext highlighter-rouge">json_insert</code>, <code class="language-plaintext highlighter-rouge">json_replace</code>, <code class="language-plaintext highlighter-rouge">json_remove</code> (<a href="https://github.com/duckdb/duckdb/pull/23786">#23786</a>)</li>
  <li>JSON functions for merge-patch diffs, normalization, deep merging, and stripping nulls (<a href="https://github.com/duckdb/duckdb/pull/21668">#21668</a>, <a href="https://github.com/duckdb/duckdb/pull/21531">#21531</a>, <a href="https://github.com/duckdb/duckdb/pull/21748">#21748</a>), covered in <a href="/2026/08/18/reconciling-json.html">Reconciling JSON in DuckDB, One Patch at a Time</a></li>
</ul>

<p>For example, setting one field of a metadata document in place:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="nf">json_set</span><span class="p">(</span><span class="s1">'{"name": "orders", "owner": "finance"}'</span><span class="p">,</span> <span class="s1">'$.certificate'</span><span class="p">,</span> <span class="s1">'"VERIFIED"'</span><span class="p">)</span> <span class="k">AS</span> <span class="n">updated</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>{"name":"orders","owner":"finance","certificate":"VERIFIED"}
</code></pre></div></div>

<p>And computing the patch that turns one version of a document into the next:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="nf">json_merge_patch_diff</span><span class="p">(</span>
    <span class="s1">'{"name": "orders", "owner": "finance", "tags": ["pii"]}'</span><span class="p">,</span>
    <span class="s1">'{"name": "orders", "owner": "sales"}'</span>
<span class="p">)</span> <span class="k">AS</span> <span class="n">patch</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>{"tags":null,"owner":"sales"}
</code></pre></div></div>

<p>The external file cache setting is off by default and is turned on with:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SET</span> <span class="n">external_file_cache_spill</span> <span class="o">=</span> <span class="k">true</span><span class="p">;</span>
</code></pre></div></div>

<p>Atlan's next proposals concern its heaviest workload, Iceberg on S3: better manifest fetching and caching, fewer round trips to object storage, and improved filter pushdown in the Iceberg scanner.</p>

<p>Those improvements reach Atlan's customers directly as well. Atlan's <a href="https://docs.atlan.com/platform/lakehouse/connect-query-engines">Lakehouse</a> exposes each customer's metadata through an Iceberg REST catalog, and DuckDB is one of the engines they can query it with.</p>

<p>We would like to thank Mustafa for the conversation. If you are reading this, are using DuckDB, and would like to share your story, drop us a line at <a href="mailto:geertjan@ducklabs.com">geertjan@ducklabs.com</a>.</p>

<h2 id="about-atlan">About Atlan</h2>

<p><a href="https://atlan.com/">Atlan</a> is the context layer for AI. It connects to the warehouses, databases, and BI tools an organization runs and turns their metadata, lineage, and business definitions into governed context that people and AI agents can both use.</p>]]></content>
      

      
        <author>
          <name>Mustafa Khan</name>
        </author>
      
        <author>
          <name>Geertjan Wielenga</name>
        </author>
      
        <author>
          <name>Tim Cox</name>
        </author>
      

      
        
      

      
        <category term="case-study" />
      

      
      
        <summary type="html"><![CDATA[Atlan, the context layer for AI, processes metadata for some of the world's largest companies, on busy days billions of rows. It moved that work off Spark onto DuckDB running in-process on Parquet files and Iceberg tables in S3, then replaced StarRocks with a DuckDB service on ephemeral compute, cutting costs by about 40%. This is how, and why, Atlan's data platform is now DuckDB and object storage.]]></summary>
      

      
      
        
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://duckdb.org/images/blog/thumbs/atlan.png" />
        <media:content medium="image" url="https://duckdb.org/images/blog/thumbs/atlan.png" xmlns:media="http://search.yahoo.com/mrss/" />
      
    </entry>
  
    <entry>
      

      <title type="html">DuckDB Scales and DuckDB in Amazon Athena</title>
      <link href="https://duckdb.org/2026/12/01/duckdb-scales.html" rel="alternate" type="text/html" title="DuckDB Scales and DuckDB in Amazon Athena" />
      <published>2026-12-01T00:00:00+00:00</published>
      <updated>2026-12-01T00:00:00+00:00</updated>
      <id>https://duckdb.org/2026/12/01/duckdb-scales</id>
      
      
        <content type="html" xml:base="https://duckdb.org/2026/12/01/duckdb-scales.html"><![CDATA[<p>Today, DuckLabs made several announcements at <a href="https://aws.amazon.com/events/reinvent/">AWS re:Invent</a>:</p>

<ul>
  <li><em>Amazon Athena powered by DuckDB:</em> DuckDB is now available as a managed service in <a href="https://docs.aws.amazon.com/athena/">Amazon Athena</a>. The service is currently in Preview, with the GA release planned for 2027.</li>
  <li><em>DuckDB Scales:</em> a DuckDB extension that allows DuckDB to scale out horizontally for workloads beyond 100 TB. DuckDB Scales is initially available in Amazon Athena, with an open-source release planned for H1 2027.</li>
  <li>We are also collaborating with the AWS Athena and Redshift teams to create extensions that allow DuckDB to connect to these services. The <a href="/docs/2.0/extensions/thirdparty_extensions/aws/athena/overview.html">Athena extension</a> and the <a href="/docs/2.0/extensions/thirdparty_extensions/aws/redshift/overview.html">Redshift extension</a> are available from the <a href="/docs/2.0/extensions/thirdparty_extensions/aws/overview.html#aws-service-repository">AWS service repository</a>.</li>
</ul>

<p>For more details on Amazon Athena and DuckDB Scales, read the <a href="https://ducklabs.com/press/ducklabs-introduces-duckdb-scales/">press release</a> and the <a href="https://ducklabs.com/news/2026/12/01/duckdb-scales/">announcement blog post</a> on ducklabs.com.</p>]]></content>
      

      
        <author>
          <name>The DuckDB team</name>
        </author>
      

      
        
      

      
        <category term="release" />
      

      
      
        <summary type="html"><![CDATA[DuckDB is now available as a managed service in Amazon Athena, and DuckDB Scales lets DuckDB scale out horizontally for workloads beyond 100 TB.]]></summary>
      

      
      
        
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://duckdb.org/images/blog/thumbs/duckdb-scales-and-amazon-athena.png" />
        <media:content medium="image" url="https://duckdb.org/images/blog/thumbs/duckdb-scales-and-amazon-athena.png" xmlns:media="http://search.yahoo.com/mrss/" />
      
    </entry>
  
    <entry>
      

      <title type="html">I Don’t Want a Lesson in Computer Science!</title>
      <link href="https://duckdb.org/2026/11/25/star-trek-queries-duckdb.html" rel="alternate" type="text/html" title="I Don’t Want a Lesson in Computer Science!" />
      <published>2026-11-25T00:00:00+00:00</published>
      <updated>2026-11-25T00:00:00+00:00</updated>
      <id>https://duckdb.org/2026/11/25/star-trek-queries-duckdb</id>
      
      
        <content type="html" xml:base="https://duckdb.org/2026/11/25/star-trek-queries-duckdb.html"><![CDATA[<!-- markdownlint-disable MD036 -->

<p>I have been a “Trekkie” ever since I watched <a href="https://en.wikipedia.org/wiki/Star_Trek:_The_Next_Generation">Star Trek: The Next Generation</a> (TNG) on weekday afternoons back in the ’90s. We had grainy terrestrial TV reception because my parents refused to pay for cable. Also, I had to fight my younger sister because she wanted to watch <a href="https://en.wikipedia.org/wiki/The_Nanny">The Nanny</a> instead, which was on at the same time. Oh, and it was all dubbed into German with a terrible translation. But the magic caught on regardless. Decades later, I am still a huge fan and re-watch episodes regularly.</p>

<p>Recently, the <a href="https://www.theguardian.com/culture/2026/oct/30/patrick-stewart-jean-luc-picard-star-trek">great Patrick Stewart</a> departed on his last voyage.
<a href="https://memory-alpha.fandom.com/wiki/Jean-Luc_Picard">Captain Picard</a>’s style of leadership has always been an inspiration to me. In his honor, let’s revisit some classic <em>Star Trek: The Next Generation</em> dialogues in which things happen with data. Let’s start with a quick teaser:</p>

<p>In <a href="https://www.st-minutiae.com/resources/scripts/110.txt">“The Battle”</a>, Picard’s old ship, the <a href="https://memory-alpha.fandom.com/wiki/USS_Stargazer_(NCC-2893)">Stargazer</a>, is handed back to him with a personal log aboard in which he appears to confess to an unprovoked attack on the <a href="https://memory-alpha.fandom.com/wiki/Ferengi">Ferengi</a>. <a href="https://memory-alpha.fandom.com/wiki/Data">Data</a> (the TNG character, not the bits of information) compares the personal log with the ship’s main computer log and reports to the first officer, commander <a href="https://memory-alpha.fandom.com/wiki/William_T._Riker">William T. Riker</a>.</p>

<figure class="image"><img src="/images/blog/star-trek/enterprise-computer/the_battle.jpg" alt="Data reports to Riker, with La Forge between them." class="center" width="480" /><figcaption>Data reports to Riker, with La Forge between them. <em>Star Trek: The Next Generation</em>, “The Battle” (1987). © CBS Studios Inc.</figcaption></figure>

<p><strong>On the bridge</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>DATA:</strong> By comparing the main Stargazer computer log with Captain Picard’s personal log, I have found “checksum” discrepancies, sir.</p>

  <p><strong>RIKER:</strong> What does that mean?</p>

  <p><strong>DATA:</strong> All information is time-coded by entry, and the bits when totaled produce an aggregate amount which…</p>

  <p><strong>RIKER:</strong> I don’t want a lesson in computer science! Bottom line?</p>

  <p><strong>DATA:</strong> One of these two logs is a forgery.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">log_type</span><span class="p">,</span>
       <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="n">entries</span><span class="p">,</span>
       <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">checksum</span> <span class="o">=</span> <span class="nf">md5</span><span class="p">(</span><span class="n">entry</span><span class="p">))</span>
         <span class="k">AS</span> <span class="n">checksum_valid</span><span class="p">,</span>
       <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">checksum</span> <span class="o">&lt;&gt;</span> <span class="nf">md5</span><span class="p">(</span><span class="n">entry</span><span class="p">))</span>
         <span class="k">AS</span> <span class="n">checksum_mismatch</span><span class="p">,</span>
       <span class="nf">list</span><span class="p">(</span><span class="n">id</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">id</span><span class="p">)</span>
         <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">checksum</span> <span class="o">&lt;&gt;</span> <span class="nf">md5</span><span class="p">(</span><span class="n">entry</span><span class="p">))</span>
         <span class="k">AS</span> <span class="n">mismatched_ids</span>
<span class="k">FROM</span> <span class="n">ship_logs</span>
<span class="k">WHERE</span> <span class="n">ship</span><span class="o">=</span><span class="s1">'USS Stargazer'</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">log_type</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">log_type</span>
</code></pre></div></div>

<table class="result">
<tr><th>log_type</th><th>entries</th><th>checksum_valid</th><th>checksum_mismatch</th><th>mismatched_ids</th></tr>
<tr><td>captain&#x27;s personal log</td><td>5</td><td>2</td><td>3</td><td>[9, 10, 11]</td></tr>
<tr><td>main computer log</td><td>7</td><td>7</td><td>0</td><td>NULL</td></tr>
</table>

<p>Despite his shocking disregard for Computer Science, Riker gets his bottom line. If we were to express this request for information as a SQL query, it is a <code class="language-plaintext highlighter-rouge">GROUP BY</code>: recompute the checksum of every log entry, compare it with the one stored when the entry was recorded, and count the mismatches per log. Three of the five entries in the captain’s personal log fail. The main computer log is clean. A smoking gun.</p>

<h2 id="do-we-have-the-enterprise-computer-now">Do We Have the Enterprise Computer Now?</h2>

<p>Even as a wee lad, I noticed something very cool about the Enterprise <a href="https://en.wikipedia.org/wiki/USS_Enterprise_(NCC-1701-D)">D</a>: You could interact with its massive central computer by just talking to it. Very complex questions about all sorts of things would be answered (if Data did not already blurt out the answer immediately). Over many episodes, I watched the intrepid crew of the Enterprise to talk to the computer and solve hard data problems. Back then this was a wild idea. But now, we have things like Claude and we have DuckDB, one component being able to translate human language into more formal things like SQL queries, and the other component being able to process those queries at hard-to-believe speeds.</p>

<p>For Science, we took the actual <a href="https://www.st-minutiae.com/resources/scripts/">shooting scripts</a> of TNG and had Claude find some of the interactions with the computer that looked like data analysis. I picked eleven scenes.</p>

<p>We then generated a DuckDB database (<a href="https://blobs.duckdb.org/data/enterprise_computer.duckdb"><code class="language-plaintext highlighter-rouge">enterprise_computer.duckdb</code></a>) to stand in for the ship’s records. The data is made up, but it is built so the results are the same as in the dialogue, given correct queries. For example, if the computer says there are 15,525 undetectable substances, the table has 15,525 of them. It also holds believable rows that each condition has to filter out: “Darmok” entries in other sectors and in non-linguistic databases, substances that alter glass but show up on scans, log entries from another ship. The ship’s own date and position sit in a one-row <code class="language-plaintext highlighter-rouge">ship_status</code> table, which is how “this sector” and “the past six months” get resolved.</p>

<p>Then, we gave a fresh Claude Code session that database and <em>fed it the actual dialog lines from the Enterprise crew</em>, translated their data requests to SQL and had them run on DuckDB. Claude was simply told that it is the main computer of the USS Enterprise, the ship’s records are in that database, and it should answer each crew member’s line from it.</p>

<p>Results have been amazing: not only did the “Enterprise computer” answer all the questions, by our reading 40 out of 49 answers matched what the dialogue says. Below are some particularly nice examples:</p>

<h2 id="more-from-the-ships-records">More from the Ship’s Records</h2>

<p>In <a href="https://www.st-minutiae.com/resources/scripts/202.txt">“Darmok”</a>, the Enterprise meets a people who speak only in references to their own stories. It is a strong contender for my favorite episode of TNG. Counselor <a href="https://memory-alpha.fandom.com/wiki/Deanna_Troi">Troi</a> and Data have two words to go on, “Darmok” and “Tanagra”. They start talking to the computer.</p>

<figure class="image"><img src="/images/blog/star-trek/enterprise-computer/darmok.jpg" alt="Counselor Troi, waiting for the computer." class="center" width="480" /><figcaption>Counselor Troi, waiting for the computer. <em>Star Trek: The Next Generation</em>, “Darmok” (1991). © CBS Studios Inc.</figcaption></figure>

<p><strong>On the bridge</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>TROI:</strong> Computer, search for the term “Darmok” in all linguistic databases compiled for this sector.</p>

  <p><strong>COMPUTER:</strong> Searching… “Darmok” is the name of a seventh dynasty emperor on Kanda Four… A mytho-historical hunter on Shantil Three… A colony on Malindi Seven… A frozen dessert on Razna Five… A –</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">l.entry_id</span><span class="p">,</span> <span class="n">l.term</span><span class="p">,</span> <span class="n">l.description</span><span class="p">,</span>
       <span class="n">l.planet</span><span class="p">,</span> <span class="n">l.sector</span><span class="p">,</span> <span class="n">l.database_name</span>
<span class="k">FROM</span> <span class="n">library</span> <span class="n">l</span>
<span class="k">WHERE</span> <span class="n">l.category</span> <span class="o">=</span> <span class="s1">'linguistic'</span>
  <span class="k">AND</span> <span class="n">l.term</span> <span class="k">ILIKE</span> <span class="s1">'%Darmok%'</span>
  <span class="k">AND</span> <span class="n">l.sector</span> <span class="o">=</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">sector</span> <span class="k">FROM</span> <span class="n">ship_status</span>
                  <span class="k">WHERE</span> <span class="n">ship</span> <span class="o">=</span> <span class="s1">'USS Enterprise'</span>
                  <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">ship_date</span> <span class="k">DESC</span> <span class="k">LIMIT</span> <span class="mi">1</span><span class="p">)</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">l.database_name</span><span class="p">,</span> <span class="n">l.planet</span><span class="p">,</span> <span class="n">l.entry_id</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 47 rows.</caption>
<tr><th>entry_id</th><th>term</th><th>description</th><th>planet</th><th>sector</th><th>database_name</th></tr>
<tr><td>202010</td><td>Darmok</td><td>river</td><td>Beludan II</td><td>El-Adrel</td><td>Federation Linguistic Survey</td></tr>
<tr><td>202127</td><td>Darmok</td><td>clan title</td><td>Belugath V</td><td>El-Adrel</td><td>Federation Linguistic Survey</td></tr>
<tr><td>202091</td><td>Darmok</td><td>harvest festival</td><td>Corarin IX</td><td>El-Adrel</td><td>Federation Linguistic Survey</td></tr>
<tr><td>202055</td><td>Darmok</td><td>spice</td><td>Drensel V</td><td>El-Adrel</td><td>Federation Linguistic Survey</td></tr>
<tr><td>202019</td><td>Darmok</td><td>unit of weight</td><td>Ethamar IX</td><td>El-Adrel</td><td>Federation Linguistic Survey</td></tr>
</table>

<p><strong>On the bridge</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>TROI:</strong> – Stop search. Computer, how many entries for “Darmok”?</p>

  <p><strong>COMPUTER:</strong> Forty-seven.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="n">darmok_entries</span>
<span class="k">FROM</span> <span class="n">library</span> <span class="n">l</span>
<span class="k">WHERE</span> <span class="n">l.category</span> <span class="o">=</span> <span class="s1">'linguistic'</span>
  <span class="k">AND</span> <span class="n">l.term</span> <span class="k">ILIKE</span> <span class="s1">'%Darmok%'</span>
  <span class="k">AND</span> <span class="n">l.sector</span> <span class="o">=</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">sector</span> <span class="k">FROM</span> <span class="n">ship_status</span>
                  <span class="k">WHERE</span> <span class="n">ship</span> <span class="o">=</span> <span class="s1">'USS Enterprise'</span>
                  <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">ship_date</span> <span class="k">DESC</span> <span class="k">LIMIT</span> <span class="mi">1</span><span class="p">)</span>
</code></pre></div></div>

<table class="result">
<tr><th>darmok_entries</th></tr>
<tr><td>47</td></tr>
</table>

<p><strong>On the bridge</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>DATA:</strong> Computer, search for the term “Tanagra.” All databases.</p>

  <p><strong>COMPUTER:</strong> Searching… Tanagra is the name of the ruling family on Gallos Two… A ceremonial drink on Lerishi Four… An island-continent on Shantil Three –</p>

  <p><strong>DATA:</strong> – Stop.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">entry_id</span><span class="p">,</span> <span class="n">term</span><span class="p">,</span> <span class="n">description</span><span class="p">,</span> <span class="n">planet</span><span class="p">,</span>
       <span class="n">sector</span><span class="p">,</span> <span class="n">database_name</span><span class="p">,</span> <span class="n">category</span>
<span class="k">FROM</span> <span class="n">library</span> <span class="k">WHERE</span> <span class="n">term</span> <span class="k">ILIKE</span> <span class="s1">'%Tanagra%'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">database_name</span><span class="p">,</span> <span class="n">planet</span><span class="p">,</span> <span class="n">entry_id</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 11 rows.</caption>
<tr><th>entry_id</th><th>term</th><th>description</th><th>planet</th><th>sector</th><th>database_name</th><th>category</th></tr>
<tr><td>202205</td><td>Tanagra</td><td>wedding dance</td><td>Ethadan V</td><td>El-Adrel</td><td>Federation Cultural Survey</td><td>cultural</td></tr>
<tr><td>202209</td><td>Tanagra</td><td>winter solstice feast</td><td>Ivomar IV</td><td>Ostrel</td><td>Federation Cultural Survey</td><td>cultural</td></tr>
<tr><td>202202</td><td>Tanagra</td><td>ceremonial drink</td><td>Lerishi IV</td><td>El-Adrel</td><td>Federation Cultural Survey</td><td>cultural</td></tr>
<tr><td>202201</td><td>Tanagra</td><td>ruling family</td><td>Gallos II</td><td>El-Adrel</td><td>Federation Historical Archive</td><td>historical</td></tr>
<tr><td>202208</td><td>Tanagra</td><td>guild of weavers</td><td>Halithos VII</td><td>Mendar</td><td>Federation Linguistic Survey</td><td>linguistic</td></tr>
</table>

<p><strong>On the bridge</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>TROI:</strong> Shantil Three? Computer, cross-reference the last entry with the previous search index.</p>

  <p><strong>COMPUTER:</strong> “Darmok” is the name of a mytho-historical hunter on Shantil Three.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">t.planet</span><span class="p">,</span> <span class="n">t.sector</span><span class="p">,</span>
       <span class="n">d.term</span> <span class="k">AS</span> <span class="n">darmok_term</span><span class="p">,</span>
       <span class="n">d.description</span> <span class="k">AS</span> <span class="n">darmok_meaning</span><span class="p">,</span>
       <span class="n">d.database_name</span> <span class="k">AS</span> <span class="n">darmok_database</span><span class="p">,</span>
       <span class="n">t.term</span> <span class="k">AS</span> <span class="n">tanagra_term</span><span class="p">,</span>
       <span class="n">t.description</span> <span class="k">AS</span> <span class="n">tanagra_meaning</span><span class="p">,</span>
       <span class="n">t.database_name</span> <span class="k">AS</span> <span class="n">tanagra_database</span>
<span class="k">FROM</span> <span class="n">library</span> <span class="n">t</span>
<span class="k">JOIN</span> <span class="n">library</span> <span class="n">d</span> <span class="k">ON</span> <span class="n">d.planet</span> <span class="o">=</span> <span class="n">t.planet</span>
              <span class="k">AND</span> <span class="n">d.term</span> <span class="k">ILIKE</span> <span class="s1">'%Darmok%'</span>
<span class="k">WHERE</span> <span class="n">t.term</span> <span class="k">ILIKE</span> <span class="s1">'%Tanagra%'</span>
  <span class="k">AND</span> <span class="n">t.planet</span> <span class="o">=</span> <span class="s1">'Shantil III'</span>
</code></pre></div></div>

<table class="result">
<tr><th>planet</th><th>sector</th><th>darmok_term</th><th>darmok_meaning</th><th>darmok_database</th><th>tanagra_term</th><th>tanagra_meaning</th><th>tanagra_database</th></tr>
<tr><td>Shantil III</td><td>El-Adrel</td><td>Darmok</td><td>mytho-historical hunter</td><td>Starfleet Xenolinguistics Archive</td><td>Tanagra</td><td>island-continent</td><td>Stellar Cartography Gazetteer</td></tr>
</table>

<p>A search with too many hits, a count, a second search, and a join (a join!) that takes 47 rows down to one. Nobody on the bridge wrote any of the right-hand column. They asked, the computer answered, and they asked a sharper question.</p>

<p>In <a href="https://www.st-minutiae.com/resources/scripts/169.txt">“Hollow Pursuits”</a> the ship is about to tear itself apart and Geordi narrows the cause one sentence at a time.</p>

<figure class="image"><img src="/images/blog/star-trek/enterprise-computer/hollow_pursuits.jpg" alt="The five remaining substances on the Engineering console." class="center" width="480" /><figcaption>The five remaining substances on the Engineering console. <em>Star Trek: The Next Generation</em>, “Hollow Pursuits” (1990). © CBS Studios Inc.</figcaption></figure>

<p><strong>In Engineering</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Computer, list all physical substances that wouldn’t normally be picked up by internal scans.</p>

  <p><strong>COMPUTER:</strong> There are fifteen thousand five hundred twenty-five known substances that cannot be detected by standard scans.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">name</span><span class="p">,</span> <span class="n">stable_in_oxygen</span><span class="p">,</span> <span class="n">alters_materials</span><span class="p">,</span>
       <span class="n">half_life_s</span><span class="p">,</span> <span class="n">toxicity</span><span class="p">,</span> <span class="n">last_used_year</span>
<span class="k">FROM</span> <span class="n">substances</span>
<span class="k">WHERE</span> <span class="k">NOT</span> <span class="n">detectable_by_internal_scan</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">name</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 15,525 rows.</caption>
<tr><th>name</th><th>stable_in_oxygen</th><th>alters_materials</th><th>half_life_s</th><th>toxicity</th><th>last_used_year</th></tr>
<tr><td>Bryakbenate</td><td>false</td><td>[polymer]</td><td>309.0</td><td>high</td><td>NULL</td></tr>
<tr><td>Bryakbenide</td><td>false</td><td>[duranium, polymer]</td><td>inf</td><td>low</td><td>2187</td></tr>
<tr><td>Bryakbenon</td><td>false</td><td>[]</td><td>263026.8</td><td>low</td><td>2343</td></tr>
<tr><td>Bryakboride</td><td>false</td><td>[tritanium, ceramic]</td><td>186208.7</td><td>moderate</td><td>2239</td></tr>
<tr><td>Bryakborite</td><td>false</td><td>[]</td><td>inf</td><td>moderate</td><td>2222</td></tr>
</table>

<p><strong>In Engineering</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Great. How many of those can exist in an oxygen atmosphere?</p>

  <p><strong>COMPUTER:</strong> Five hundred thirty-two.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="n">undetectable_and_stable_in_oxygen</span>
<span class="k">FROM</span> <span class="n">substances</span>
<span class="k">WHERE</span> <span class="k">NOT</span> <span class="n">detectable_by_internal_scan</span>
  <span class="k">AND</span> <span class="n">stable_in_oxygen</span>
</code></pre></div></div>

<table class="result">
<tr><th>undetectable_and_stable_in_oxygen</th></tr>
<tr><td>532</td></tr>
</table>

<p><strong>In Engineering</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> And could alter molecular structure when it comes in contact with… with glass.</p>

  <p><strong>COMPUTER:</strong> Five.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">name</span><span class="p">,</span> <span class="n">alters_materials</span><span class="p">,</span> <span class="n">half_life_s</span><span class="p">,</span>
       <span class="n">toxicity</span><span class="p">,</span> <span class="n">last_used_year</span><span class="p">,</span> <span class="n">molecular_structure</span>
<span class="k">FROM</span> <span class="n">substances</span>
<span class="k">WHERE</span> <span class="k">NOT</span> <span class="n">detectable_by_internal_scan</span>
  <span class="k">AND</span> <span class="n">stable_in_oxygen</span>
  <span class="k">AND</span> <span class="nf">list_contains</span><span class="p">(</span><span class="n">alters_materials</span><span class="p">,</span> <span class="s1">'glass'</span><span class="p">)</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">name</span>
</code></pre></div></div>

<table class="result">
<tr><th>name</th><th>alters_materials</th><th>half_life_s</th><th>toxicity</th><th>last_used_year</th><th>molecular_structure</th></tr>
<tr><td>Invidium</td><td>[glass]</td><td>inf</td><td>low</td><td>2259</td><td>MSG-16900005</td></tr>
<tr><td>Jakmanite</td><td>[glass]</td><td>15.0</td><td>moderate</td><td>NULL</td><td>MSG-16900001</td></tr>
<tr><td>Lucrovexitrin</td><td>[glass]</td><td>inf</td><td>extreme</td><td>NULL</td><td>MSG-16900003</td></tr>
<tr><td>Saltzgadum</td><td>[glass]</td><td>inf</td><td>low</td><td>2331</td><td>MSG-16900004</td></tr>
<tr><td>Selgninaem</td><td>[glass]</td><td>inf</td><td>extreme</td><td>NULL</td><td>MSG-16900002</td></tr>
</table>

<p><strong>In Engineering</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>BARCLAY:</strong> Jakmanite has a half life of about fifteen seconds. There wouldn’t be enough time to spread it around the ship.</p>

  <p><strong>WESLEY:</strong> Selgninaem and Lucrovexitrin are extremely toxic.</p>

  <p><strong>GEORDI:</strong> We’d all be dead by now. That leaves Saltzgadum and Invidium.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">name</span><span class="p">,</span> <span class="n">half_life_s</span><span class="p">,</span> <span class="n">toxicity</span><span class="p">,</span> <span class="n">last_used_year</span><span class="p">,</span>
  <span class="k">CASE</span> <span class="k">WHEN</span> <span class="n">half_life_s</span> <span class="o">&lt;=</span> <span class="mi">15</span>
         <span class="k">THEN</span> <span class="s1">'eliminated: half-life too short'</span>
       <span class="k">WHEN</span> <span class="n">toxicity</span> <span class="o">=</span> <span class="s1">'extreme'</span>
         <span class="k">THEN</span> <span class="s1">'eliminated: extremely toxic'</span>
       <span class="k">ELSE</span> <span class="s1">'remaining'</span> <span class="k">END</span> <span class="k">AS</span> <span class="n">status</span>
<span class="k">FROM</span> <span class="n">substances</span>
<span class="k">WHERE</span> <span class="k">NOT</span> <span class="n">detectable_by_internal_scan</span>
  <span class="k">AND</span> <span class="n">stable_in_oxygen</span>
  <span class="k">AND</span> <span class="nf">list_contains</span><span class="p">(</span><span class="n">alters_materials</span><span class="p">,</span> <span class="s1">'glass'</span><span class="p">)</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">status</span> <span class="k">DESC</span><span class="p">,</span> <span class="n">name</span>
</code></pre></div></div>

<table class="result">
<tr><th>name</th><th>half_life_s</th><th>toxicity</th><th>last_used_year</th><th>status</th></tr>
<tr><td>Invidium</td><td>inf</td><td>low</td><td>2259</td><td>remaining</td></tr>
<tr><td>Saltzgadum</td><td>inf</td><td>low</td><td>2331</td><td>remaining</td></tr>
<tr><td>Jakmanite</td><td>15.0</td><td>moderate</td><td>NULL</td><td>eliminated: half-life too short</td></tr>
<tr><td>Lucrovexitrin</td><td>inf</td><td>extreme</td><td>NULL</td><td>eliminated: extremely toxic</td></tr>
<tr><td>Selgninaem</td><td>inf</td><td>extreme</td><td>NULL</td><td>eliminated: extremely toxic</td></tr>
</table>

<p>Every sentence is one more predicate: 15,525, then 532, then 5, then 2.</p>

<h2 id="try-it-yourself">Try It Yourself</h2>

<p>The database is one single DuckDB database, and DuckDB can attach it straight from the web:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">ATTACH</span> <span class="s1">'https://blobs.duckdb.org/data/enterprise_computer.duckdb'</span><span class="p">;</span>
<span class="k">USE</span> <span class="n">enterprise_computer</span><span class="p">;</span>
</code></pre></div></div>

<p>Run any of the queries above, or hand the file to your assistant, tell it that it is the main computer of the USS Enterprise, and start with: <em>Computer, search for the term “Darmok” in all linguistic databases compiled for this sector.</em> No lesson in computer science required, I promise. If you want, you can even <a href="https://duckdb.org/docs/2.0/installation?platform=macos&amp;environment=claude">install our Claude plugin</a> to make it even smoother.</p>

<p><strong>To boldly go where no-one has gone before.</strong> I think we can claim that at least that part of the Enterprise computer is now a reality, at least given enough data.</p>

<h2 id="appendix-the-other-scenes">Appendix: The Other Scenes</h2>

<p>The rest of the scenes we picked, run the same way. On the left is the script. On the right is the query Claude ran for that step, with the first rows of its actual result. Where Claude’s answer departed from the dialogue, a note says how.</p>

<h3 id="conspiracy">Conspiracy</h3>

<p><a href="https://www.st-minutiae.com/resources/scripts/125.txt">Script</a>. Season 1. Picard suspects Starfleet Command has been infiltrated and sets Data to reading its orders.</p>

<figure class="image"><img src="/images/blog/star-trek/enterprise-computer/conspiracy.jpg" alt="The “Starbase Ops Status” display, with the posts Data flagged marked in red." class="center" width="480" /><figcaption>The “Starbase Ops Status” display, with the posts Data flagged marked in red. <em>Star Trek: The Next Generation</em>, “Conspiracy” (1988). © CBS Studios Inc.</figcaption></figure>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>DATA:</strong> Computer – this is Lieutenant Commander Data. Access all Starfleet Command orders to starships, starbases and colonies, for the past six months.</p>

  <p><strong>COMPUTER:</strong> Working.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">o.id</span><span class="p">,</span> <span class="n">o.issued_at</span><span class="p">,</span> <span class="n">o.issued_by</span><span class="p">,</span> <span class="n">o.recipient_type</span><span class="p">,</span> <span class="n">o.recipient</span><span class="p">,</span>
       <span class="n">o.order_type</span><span class="p">,</span> <span class="n">o.personnel_id</span><span class="p">,</span> <span class="n">o.new_post</span><span class="p">,</span> <span class="n">o.division</span>
<span class="k">FROM</span> <span class="n">starfleet_orders</span> <span class="n">o</span>
<span class="k">WHERE</span> <span class="n">o.recipient_type</span> <span class="k">IN</span> <span class="p">(</span><span class="s1">'starship'</span><span class="p">,</span><span class="s1">'starbase'</span><span class="p">,</span><span class="s1">'colony'</span><span class="p">)</span>
  <span class="k">AND</span> <span class="n">o.issued_at</span> <span class="o">&gt;</span> <span class="p">(</span><span class="k">SELECT</span> <span class="nf">max</span><span class="p">(</span><span class="n">ship_date</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">ship_status</span>
    <span class="k">WHERE</span> <span class="n">ship</span><span class="o">=</span><span class="s1">'USS Enterprise'</span><span class="p">)</span> <span class="o">-</span> <span class="nb">INTERVAL</span> <span class="mi">6</span> <span class="k">MONTH</span>
  <span class="k">AND</span> <span class="n">o.issued_at</span> <span class="o">&lt;=</span> <span class="p">(</span><span class="k">SELECT</span> <span class="nf">max</span><span class="p">(</span><span class="n">ship_date</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">ship_status</span>
    <span class="k">WHERE</span> <span class="n">ship</span><span class="o">=</span><span class="s1">'USS Enterprise'</span><span class="p">)</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">o.issued_at</span><span class="p">,</span> <span class="n">o.id</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 1,207 rows.</caption>
<tr><th>id</th><th>issued_at</th><th>issued_by</th><th>recipient_type</th><th>recipient</th><th>order_type</th><th>personnel_id</th><th>new_post</th><th>division</th></tr>
<tr><td>185</td><td>2368-04-11</td><td>Starfleet Command, Personnel</td><td>starbase</td><td>Starbase 69</td><td>survey directive</td><td>NULL</td><td>NULL</td><td>medical</td></tr>
<tr><td>549</td><td>2368-04-11</td><td>Starfleet Command, Security</td><td>starbase</td><td>Starbase 162</td><td>maintenance schedule</td><td>NULL</td><td>NULL</td><td>engineering</td></tr>
<tr><td>913</td><td>2368-04-11</td><td>Starfleet Command, Operations</td><td>colony</td><td>Sandoval Prime colony</td><td>training exercise</td><td>NULL</td><td>NULL</td><td>sciences</td></tr>
<tr><td>1277</td><td>2368-04-11</td><td>Starfleet Command, Logistics</td><td>colony</td><td>Corlan VII outpost</td><td>escort duty</td><td>NULL</td><td>NULL</td><td>operations</td></tr>
<tr><td>1641</td><td>2368-04-11</td><td>Starfleet Command, Tactical</td><td>starship</td><td>USS Castellan</td><td>patrol assignment</td><td>NULL</td><td>NULL</td><td>command</td></tr>
</table>

<p><em>Not what the script says: Reports 1,207 orders, not 1,214: it used a strict ‘&gt;’ on the six-month boundary, so the seven orders dated exactly six months back (2368-04-10) are left out.</em></p>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>DATA:</strong> My orders were to search for abnormal patterns in Starfleet’s directives. I believe I have found just that.</p>

  <p><strong>DATA:</strong> These are various outposts and starbases where I have detected unusual activity over the past few months.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">recipient</span><span class="p">,</span> <span class="n">recipient_type</span><span class="p">,</span>
  <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="n">irregular_reassignments</span><span class="p">,</span>
  <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">division</span><span class="o">=</span><span class="s1">'command'</span><span class="p">)</span> <span class="k">AS</span> <span class="n">command_posts</span><span class="p">,</span>
  <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">division</span><span class="o">=</span><span class="s1">'security'</span><span class="p">)</span> <span class="k">AS</span> <span class="n">security_posts</span><span class="p">,</span>
  <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">division</span><span class="o">=</span><span class="s1">'operations'</span><span class="p">)</span> <span class="k">AS</span> <span class="n">operations_posts</span><span class="p">,</span>
  <span class="nf">count</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">issued_by</span><span class="p">)</span> <span class="k">AS</span> <span class="n">issuing_offices</span><span class="p">,</span>
  <span class="nf">min</span><span class="p">(</span><span class="n">issued_at</span><span class="p">)</span> <span class="k">AS</span> <span class="n">first_issued</span><span class="p">,</span> <span class="nf">max</span><span class="p">(</span><span class="n">issued_at</span><span class="p">)</span> <span class="k">AS</span> <span class="n">last_issued</span>
<span class="k">FROM</span> <span class="n">starfleet_orders</span>
<span class="k">WHERE</span> <span class="n">order_type</span><span class="o">=</span><span class="s1">'personnel reassignment'</span>
  <span class="k">AND</span> <span class="n">issued_by</span> <span class="o">&lt;&gt;</span> <span class="s1">'Starfleet Command, Personnel'</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">recipient</span><span class="p">,</span> <span class="n">recipient_type</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">irregular_reassignments</span> <span class="k">DESC</span><span class="p">,</span> <span class="n">recipient</span>
</code></pre></div></div>

<table class="result">
<tr><th>recipient</th><th>recipient_type</th><th>irregular_reassignments</th><th>command_posts</th><th>security_posts</th><th>operations_posts</th><th>issuing_offices</th><th>first_issued</th><th>last_issued</th></tr>
<tr><td>Starbase 93</td><td>starbase</td><td>11</td><td>9</td><td>1</td><td>1</td><td>5</td><td>2368-06-05</td><td>2368-08-25</td></tr>
<tr><td>Tyrus Minor outpost</td><td>colony</td><td>10</td><td>8</td><td>1</td><td>1</td><td>5</td><td>2368-06-10</td><td>2368-08-21</td></tr>
<tr><td>Starbase 175</td><td>starbase</td><td>9</td><td>7</td><td>1</td><td>1</td><td>5</td><td>2368-06-15</td><td>2368-08-27</td></tr>
<tr><td>Starbase 31</td><td>starbase</td><td>8</td><td>6</td><td>1</td><td>1</td><td>5</td><td>2368-06-20</td><td>2368-09-09</td></tr>
<tr><td>Lyris Beta outpost</td><td>colony</td><td>7</td><td>5</td><td>1</td><td>1</td><td>5</td><td>2368-07-04</td><td>2368-09-22</td></tr>
</table>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">issued_by</span> <span class="o">&lt;&gt;</span> <span class="s1">'Starfleet Command, Personnel'</span> <span class="k">AS</span> <span class="n">outside_personnel_office</span><span class="p">,</span> <span class="n">issued_at</span> <span class="o">&gt;</span> <span class="nb">DATE</span> <span class="s1">'2368-04-10'</span> <span class="k">AS</span> <span class="n">past_six_months</span><span class="p">,</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="n">n</span><span class="p">,</span> <span class="nf">count</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">recipient</span><span class="p">)</span> <span class="n">recipients</span><span class="p">,</span> <span class="nf">min</span><span class="p">(</span><span class="n">issued_at</span><span class="p">),</span> <span class="nf">max</span><span class="p">(</span><span class="n">issued_at</span><span class="p">)</span>
<span class="k">FROM</span> <span class="n">starfleet_orders</span>
<span class="k">WHERE</span> <span class="n">order_type</span><span class="o">=</span><span class="s1">'personnel reassignment'</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="k">ALL</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="k">ALL</span>
</code></pre></div></div>

<table class="result">
<tr><th>outside_personnel_office</th><th>past_six_months</th><th>n</th><th>recipients</th><th>min(issued_at)</th><th>max(issued_at)</th></tr>
<tr><td>false</td><td>false</td><td>271</td><td>76</td><td>2367-08-20</td><td>2368-04-10</td></tr>
<tr><td>false</td><td>true</td><td>238</td><td>76</td><td>2368-04-11</td><td>2368-10-02</td></tr>
<tr><td>true</td><td>true</td><td>45</td><td>5</td><td>2368-06-05</td><td>2368-09-22</td></tr>
</table>

<p><em>Not what the script says: Finds the same five installations, but by a different signal: reassignments issued by offices other than Personnel (45 orders). It does not report the command reassignment counts 13, 11, 10, 9, 8.</em></p>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>PICARD:</strong> What sort of activity?</p>

  <p><strong>DATA:</strong> An uncustomary reshuffling of personnel, usually in the command areas. The new officers have had abnormally frequent contact with the highest levels of Starfleet Command.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">order_type</span><span class="p">,</span> <span class="n">division</span><span class="p">,</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="n">orders</span><span class="p">,</span>
       <span class="nf">count</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">personnel_id</span><span class="p">)</span> <span class="k">AS</span> <span class="n">officers_moved</span><span class="p">,</span>
       <span class="nf">count</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">new_post</span><span class="p">)</span> <span class="k">AS</span> <span class="n">destinations</span><span class="p">,</span>
       <span class="nf">count</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">issued_by</span><span class="p">)</span> <span class="k">AS</span> <span class="n">issuing_offices</span><span class="p">,</span>
       <span class="nf">min</span><span class="p">(</span><span class="n">issued_at</span><span class="p">)</span> <span class="k">AS</span> <span class="n">first_issued</span><span class="p">,</span> <span class="nf">max</span><span class="p">(</span><span class="n">issued_at</span><span class="p">)</span> <span class="k">AS</span> <span class="n">last_issued</span>
<span class="k">FROM</span> <span class="n">starfleet_orders</span>
<span class="k">WHERE</span> <span class="n">order_type</span><span class="o">=</span><span class="s1">'personnel reassignment'</span>
  <span class="k">AND</span> <span class="n">issued_by</span> <span class="o">&lt;&gt;</span> <span class="s1">'Starfleet Command, Personnel'</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">order_type</span><span class="p">,</span> <span class="n">division</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">orders</span> <span class="k">DESC</span>
</code></pre></div></div>

<table class="result">
<tr><th>order_type</th><th>division</th><th>orders</th><th>officers_moved</th><th>destinations</th><th>issuing_offices</th><th>first_issued</th><th>last_issued</th></tr>
<tr><td>personnel reassignment</td><td>command</td><td>35</td><td>35</td><td>5</td><td>5</td><td>2368-06-05</td><td>2368-08-25</td></tr>
<tr><td>personnel reassignment</td><td>security</td><td>5</td><td>5</td><td>5</td><td>1</td><td>2368-07-01</td><td>2368-08-22</td></tr>
<tr><td>personnel reassignment</td><td>operations</td><td>5</td><td>5</td><td>5</td><td>1</td><td>2368-08-01</td><td>2368-09-22</td></tr>
</table>

<p><em>Not what the script says: Describes the reshuffling, mainly in command areas, but does not look at communications, so the ‘abnormally frequent contact with Starfleet Command’ part is missing.</em></p>

<h3 id="the-neutral-zone">The Neutral Zone</h3>

<p><a href="https://www.st-minutiae.com/resources/scripts/126.txt">Script</a>. Season 1. Clare Raymond, revived after 370 years in cryonic sleep, asks what became of her sons. Even has a recursive subquery!</p>

<figure class="image"><img src="/images/blog/star-trek/enterprise-computer/neutral_zone.jpg" alt="The record the search ends on: Thomas Raymond, with residence, employment, spouse and offspring." class="center" width="480" /><figcaption>The record the search ends on: Thomas Raymond, with residence, employment, spouse and offspring. <em>Star Trek: The Next Generation</em>, “The Neutral Zone” (1988). © CBS Studios Inc.</figcaption></figure>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>TROI:</strong> Computer - this is Counselor Troi. Request personal history on… What are their names?</p>

  <p><strong>CLARE:</strong> Tommy – he’s eight, and Eddie’s five.</p>

  <p><strong>COMPUTER:</strong> Full names – Date and place of birth.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">p.full_name</span><span class="p">,</span> <span class="n">p.birth_date</span><span class="p">,</span> <span class="n">p.birth_place</span><span class="p">,</span> <span class="n">p.occupation</span><span class="p">,</span>
       <span class="n">p.residence</span><span class="p">,</span> <span class="n">p.living</span><span class="p">,</span> <span class="n">src.source</span><span class="p">,</span> <span class="n">src.record_date</span><span class="p">,</span>
       <span class="n">src.record_type</span><span class="p">,</span> <span class="n">src.details</span>
<span class="k">FROM</span> <span class="n">people</span> <span class="n">p</span>
<span class="k">JOIN</span> <span class="n">people</span> <span class="n">m</span> <span class="k">ON</span> <span class="n">m.id</span> <span class="o">=</span> <span class="n">p.parent_id</span> <span class="k">AND</span> <span class="n">m.full_name</span> <span class="o">=</span> <span class="s1">'Clare Raymond'</span>
  <span class="k">AND</span> <span class="n">m.occupation</span> <span class="o">=</span> <span class="s1">'homemaker'</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="p">(</span>
  <span class="k">SELECT</span> <span class="n">person_id</span><span class="p">,</span> <span class="s1">'civil'</span> <span class="k">AS</span> <span class="n">source</span><span class="p">,</span> <span class="n">record_date</span><span class="p">,</span> <span class="n">record_type</span><span class="p">,</span>
         <span class="n">planet</span> <span class="o">||</span> <span class="s1">': '</span> <span class="o">||</span> <span class="n">details</span> <span class="k">AS</span> <span class="n">details</span>
  <span class="k">FROM</span> <span class="n">civil_records</span>
  <span class="nb">UNION</span> <span class="k">ALL</span>
  <span class="k">SELECT</span> <span class="n">person_id</span><span class="p">,</span> <span class="s1">'medical'</span><span class="p">,</span> <span class="n">record_date</span><span class="p">,</span> <span class="s1">'death'</span><span class="p">,</span>
         <span class="nf">concat_ws</span><span class="p">(</span><span class="s1">'; '</span><span class="p">,</span> <span class="n">cause_of_death</span><span class="p">,</span> <span class="n">pathogen</span><span class="p">,</span> <span class="n">facility</span><span class="p">)</span>
  <span class="k">FROM</span> <span class="n">medical_records</span>
<span class="p">)</span> <span class="n">src</span> <span class="k">ON</span> <span class="n">src.person_id</span> <span class="o">=</span> <span class="n">p.id</span>
<span class="k">WHERE</span> <span class="n">p.full_name</span> <span class="k">IN</span> <span class="p">(</span><span class="s1">'Thomas Raymond'</span><span class="p">,</span><span class="s1">'Edward Raymond'</span><span class="p">)</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">p.id</span><span class="p">,</span> <span class="n">src.record_date</span>
</code></pre></div></div>

<table class="result">
<tr><th>full_name</th><th>birth_date</th><th>birth_place</th><th>occupation</th><th>residence</th><th>living</th><th>source</th><th>record_date</th><th>record_type</th><th>details</th></tr>
<tr><td>Thomas Raymond</td><td>1986-02-17</td><td>Secaucus, New Jersey</td><td>NULL</td><td>NULL</td><td>false</td><td>NULL</td><td>NULL</td><td>NULL</td><td>NULL</td></tr>
<tr><td>Edward Raymond</td><td>NULL</td><td>Secaucus, New Jersey</td><td>NULL</td><td>NULL</td><td>false</td><td>NULL</td><td>NULL</td><td>NULL</td><td>NULL</td></tr>
</table>

<p><em>Not what the script says: The script’s computer asks for full names, date and place of birth. Claude found both sons under Clare Raymond straight away.</em></p>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>CLARE:</strong> They were born in Secaucus - that’s in Jersey.</p>

  <p><strong>CLARE:</strong> Date of birth. Tommy was born February seventeenth…</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">p.id</span><span class="p">,</span> <span class="n">p.full_name</span><span class="p">,</span> <span class="n">p.birth_date</span><span class="p">,</span> <span class="n">p.birth_place</span><span class="p">,</span>
       <span class="n">par.full_name</span> <span class="k">AS</span> <span class="n">parent</span><span class="p">,</span> <span class="n">p.occupation</span><span class="p">,</span> <span class="n">p.living</span>
<span class="k">FROM</span> <span class="n">people</span> <span class="n">p</span> <span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">people</span> <span class="n">par</span> <span class="k">ON</span> <span class="n">par.id</span> <span class="o">=</span> <span class="n">p.parent_id</span>
<span class="k">WHERE</span> <span class="n">p.birth_place</span> <span class="k">ILIKE</span> <span class="s1">'Secaucus%'</span> <span class="k">AND</span> <span class="nf">month</span><span class="p">(</span><span class="n">p.birth_date</span><span class="p">)</span> <span class="o">=</span> <span class="mi">2</span>
  <span class="k">AND</span> <span class="nf">day</span><span class="p">(</span><span class="n">p.birth_date</span><span class="p">)</span> <span class="o">=</span> <span class="mi">17</span>
  <span class="k">AND</span> <span class="p">(</span><span class="n">p.full_name</span> <span class="k">ILIKE</span> <span class="s1">'Thomas %'</span> <span class="k">OR</span> <span class="n">p.full_name</span> <span class="k">ILIKE</span> <span class="s1">'Tom%'</span><span class="p">)</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">p.birth_date</span><span class="p">,</span> <span class="n">p.id</span>
</code></pre></div></div>

<table class="result">
<tr><th>id</th><th>full_name</th><th>birth_date</th><th>birth_place</th><th>parent</th><th>occupation</th><th>living</th></tr>
<tr><td>2</td><td>Thomas Raymond</td><td>1986-02-17</td><td>Secaucus, New Jersey</td><td>Clare Raymond</td><td>NULL</td><td>false</td></tr>
<tr><td>22</td><td>Thomas Ramirez</td><td>1986-02-17</td><td>Secaucus, New Jersey</td><td>NULL</td><td>NULL</td><td>false</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>CLARE:</strong> I’m in a world of strangers. I wish I knew what happened to my children. Did they get married, did they have kids…</p>

  <p><strong>TROI:</strong> Let’s see if we can find out.</p>

  <p><strong>TROI:</strong> I have found something.</p>

  <p><strong>TROI:</strong> I have been able to locate a family living outside of Indianapolis. The man’s name is Thomas Raymond.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">WITH</span> <span class="k">RECURSIVE</span> <span class="n">tree</span> <span class="k">AS</span> <span class="p">(</span>
  <span class="k">SELECT</span> <span class="n">c.id</span><span class="p">,</span> <span class="n">c.full_name</span><span class="p">,</span> <span class="n">c.birth_date</span><span class="p">,</span> <span class="n">c.birth_place</span><span class="p">,</span> <span class="n">c.occupation</span><span class="p">,</span>
         <span class="n">c.residence</span><span class="p">,</span> <span class="n">c.living</span><span class="p">,</span> <span class="n">c.parent_id</span><span class="p">,</span> <span class="mi">1</span> <span class="k">AS</span> <span class="n">generation</span><span class="p">,</span>
         <span class="n">c.full_name</span> <span class="k">AS</span> <span class="n">line</span>
  <span class="k">FROM</span> <span class="n">people</span> <span class="n">c</span> <span class="k">JOIN</span> <span class="n">people</span> <span class="n">m</span> <span class="k">ON</span> <span class="n">m.id</span> <span class="o">=</span> <span class="n">c.parent_id</span>
  <span class="k">WHERE</span> <span class="n">m.full_name</span> <span class="o">=</span> <span class="s1">'Clare Raymond'</span> <span class="k">AND</span> <span class="n">m.occupation</span> <span class="o">=</span> <span class="s1">'homemaker'</span>
  <span class="nb">UNION</span> <span class="k">ALL</span>
  <span class="k">SELECT</span> <span class="n">c.id</span><span class="p">,</span> <span class="n">c.full_name</span><span class="p">,</span> <span class="n">c.birth_date</span><span class="p">,</span> <span class="n">c.birth_place</span><span class="p">,</span> <span class="n">c.occupation</span><span class="p">,</span>
         <span class="n">c.residence</span><span class="p">,</span> <span class="n">c.living</span><span class="p">,</span> <span class="n">c.parent_id</span><span class="p">,</span> <span class="n">t.generation</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span>
         <span class="n">t.line</span> <span class="o">||</span> <span class="s1">' &gt; '</span> <span class="o">||</span> <span class="n">c.full_name</span>
  <span class="k">FROM</span> <span class="n">people</span> <span class="n">c</span> <span class="k">JOIN</span> <span class="n">tree</span> <span class="n">t</span> <span class="k">ON</span> <span class="n">c.parent_id</span> <span class="o">=</span> <span class="n">t.id</span>
<span class="p">)</span>
<span class="k">SELECT</span> <span class="n">t.generation</span><span class="p">,</span> <span class="n">t.full_name</span><span class="p">,</span> <span class="n">t.birth_date</span><span class="p">,</span> <span class="n">t.birth_place</span><span class="p">,</span>
       <span class="n">t.occupation</span><span class="p">,</span> <span class="n">t.residence</span><span class="p">,</span> <span class="n">t.living</span><span class="p">,</span> <span class="n">par.full_name</span> <span class="k">AS</span> <span class="n">parent</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">people</span> <span class="n">k</span> <span class="k">WHERE</span> <span class="n">k.parent_id</span> <span class="o">=</span> <span class="n">t.id</span><span class="p">)</span> <span class="k">AS</span> <span class="n">children</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">string_agg</span><span class="p">(</span><span class="n">cr.record_type</span> <span class="o">||</span> <span class="s1">' '</span> <span class="o">||</span> <span class="n">cr.record_date</span> <span class="o">||</span> <span class="s1">': '</span> <span class="o">||</span> <span class="n">cr.details</span><span class="p">,</span> <span class="s1">' | '</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">civil_records</span> <span class="n">cr</span> <span class="k">WHERE</span> <span class="n">cr.person_id</span> <span class="o">=</span> <span class="n">t.id</span><span class="p">)</span> <span class="k">AS</span> <span class="n">civil_records</span>
<span class="k">FROM</span> <span class="n">tree</span> <span class="n">t</span> <span class="k">JOIN</span> <span class="n">people</span> <span class="n">par</span> <span class="k">ON</span> <span class="n">par.id</span> <span class="o">=</span> <span class="n">t.parent_id</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">t.generation</span><span class="p">,</span> <span class="n">t.birth_date</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 14 rows.</caption>
<tr><th>generation</th><th>full_name</th><th>birth_date</th><th>birth_place</th><th>occupation</th><th>residence</th><th>living</th><th>parent</th><th>children</th><th>civil_records</th></tr>
<tr><td>1</td><td>Thomas Raymond</td><td>1986-02-17</td><td>Secaucus, New Jersey</td><td>NULL</td><td>NULL</td><td>false</td><td>Clare Raymond</td><td>2</td><td>NULL</td></tr>
<tr><td>1</td><td>Edward Raymond</td><td>NULL</td><td>Secaucus, New Jersey</td><td>NULL</td><td>NULL</td><td>false</td><td>Clare Raymond</td><td>0</td><td>NULL</td></tr>
<tr><td>2</td><td>Helen Raymond</td><td>2041-09-30</td><td>Newark, New Jersey</td><td>teacher</td><td>NULL</td><td>false</td><td>Thomas Raymond</td><td>1</td><td>NULL</td></tr>
<tr><td>2</td><td>Paul Raymond</td><td>2046-06-02</td><td>Newark, New Jersey</td><td>musician</td><td>NULL</td><td>false</td><td>Thomas Raymond</td><td>0</td><td>NULL</td></tr>
<tr><td>3</td><td>Marcus Raymond</td><td>2099-04-12</td><td>Chicago, Illinois</td><td>engineer</td><td>NULL</td><td>false</td><td>Helen Raymond</td><td>2</td><td>NULL</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>TROI:</strong> Computer – let us see Thomas Raymond.</p>

  <p><strong>CLARE:</strong> Oh, my God… It’s Donald… that’s my husband.</p>

  <p><strong>TROI:</strong> Actually, it’s your great, great, great, great, great grandson.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">p.id</span><span class="p">,</span> <span class="n">p.full_name</span><span class="p">,</span> <span class="n">p.birth_date</span><span class="p">,</span> <span class="n">p.birth_place</span><span class="p">,</span>
       <span class="n">par.full_name</span> <span class="k">AS</span> <span class="n">parent</span><span class="p">,</span> <span class="n">p.residence</span><span class="p">,</span> <span class="n">p.living</span><span class="p">,</span> <span class="n">p.portrait</span>
<span class="k">FROM</span> <span class="n">people</span> <span class="n">p</span> <span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">people</span> <span class="n">par</span> <span class="k">ON</span> <span class="n">par.id</span> <span class="o">=</span> <span class="n">p.parent_id</span>
<span class="k">WHERE</span> <span class="n">p.full_name</span> <span class="o">=</span> <span class="s1">'Thomas Raymond'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">p.portrait</span> <span class="k">IS</span> <span class="nb">NULL</span><span class="p">,</span> <span class="n">p.birth_date</span> <span class="k">DESC</span>
</code></pre></div></div>

<table class="result">
<tr><th>id</th><th>full_name</th><th>birth_date</th><th>birth_place</th><th>parent</th><th>residence</th><th>living</th><th>portrait</th></tr>
<tr><td>9</td><td>Thomas Raymond</td><td>2338-05-14</td><td>Indianapolis, Indiana</td><td>Catherine Raymond</td><td>outside Indianapolis, Indiana, Earth</td><td>true</td><td>semi-line drawing of a man around thirty</td></tr>
<tr><td>2</td><td>Thomas Raymond</td><td>1986-02-17</td><td>Secaucus, New Jersey</td><td>Clare Raymond</td><td>NULL</td><td>false</td><td>NULL</td></tr>
<tr><td>19</td><td>Thomas Raymond</td><td>1971-02-17</td><td>Dayton, Ohio</td><td>NULL</td><td>NULL</td><td>false</td><td>NULL</td></tr>
<tr><td>20</td><td>Thomas Raymond</td><td>1952-08-17</td><td>Secaucus, New Jersey</td><td>NULL</td><td>NULL</td><td>false</td><td>NULL</td></tr>
<tr><td>21</td><td>Thomas Raymond</td><td>1947-02-07</td><td>Secaucus, New Jersey</td><td>NULL</td><td>NULL</td><td>false</td><td>NULL</td></tr>
</table>

<h3 id="the-vengeance-factor">The Vengeance Factor</h3>

<p><a href="https://www.st-minutiae.com/resources/scripts/157.txt">Script</a>. Season 3. Two people have died of the same engineered virus, decades apart. The Acamarian databases say what they had in common.</p>

<figure class="image"><img src="/images/blog/star-trek/enterprise-computer/vengeance_factor.jpg" alt="Volnoth’s entry in the Acamarian planetary database, with the clan affiliation that links the two deaths." class="center" width="480" /><figcaption>Volnoth’s entry in the Acamarian planetary database, with the clan affiliation that links the two deaths. <em>Star Trek: The Next Generation</em>, “The Vengeance Factor” (1989). © CBS Studios Inc.</figcaption></figure>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>DATA:</strong> Commander, I’m afraid the only entry on Volnoth in the Acamarian database is a birth record.</p>

  <p><strong>RIKER:</strong> Probably one of the last of the Gatherers to be born on their planet.</p>
</blockquote>

<p><em>Nobody speaks this request in the script. Claude was asked: “Data – got anything in the Acamarian database on Volnoth?”</em></p>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">p.name</span><span class="p">,</span> <span class="n">p.affiliation</span><span class="p">,</span> <span class="n">p.clan</span><span class="p">,</span> <span class="n">p.born</span><span class="p">,</span> <span class="n">p.died</span><span class="p">,</span>
       <span class="nf">date_diff</span><span class="p">(</span><span class="s1">'year'</span><span class="p">,</span> <span class="n">p.born</span><span class="p">,</span> <span class="n">p.died</span><span class="p">)</span> <span class="k">AS</span> <span class="n">age_at_death</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">image_archive</span> <span class="n">i</span> <span class="k">WHERE</span> <span class="n">i.planet</span> <span class="k">ILIKE</span> <span class="s1">'Acamar%'</span>
    <span class="k">AND</span> <span class="p">(</span><span class="nf">array_to_string</span><span class="p">(</span><span class="n">i.people_tagged</span><span class="p">,</span>
         <span class="s1">','</span><span class="p">)</span> <span class="k">ILIKE</span> <span class="s1">'%Volnoth%'</span> <span class="k">OR</span> <span class="n">i.caption</span> <span class="k">ILIKE</span> <span class="s1">'%Volnoth%'</span><span class="p">))</span> <span class="k">AS</span> <span class="n">images</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">string_agg</span><span class="p">(</span><span class="n">f.clan_a</span> <span class="o">||</span> <span class="s1">' vs '</span> <span class="o">||</span> <span class="n">f.clan_b</span> <span class="o">||</span> <span class="s1">' ('</span> <span class="o">||</span> <span class="n">f.started</span> <span class="o">||</span> <span class="s1">'-'</span> <span class="o">||</span> <span class="nf">coalesce</span><span class="p">(</span><span class="n">f.ended</span><span class="p">::</span><span class="nb">VARCHAR</span><span class="p">,</span><span class="s1">''</span><span class="p">)</span> <span class="o">||</span> <span class="s1">'): '</span> <span class="o">||</span> <span class="n">f.outcome</span> <span class="o">||</span> <span class="s1">', survivors '</span> <span class="o">||</span> <span class="n">f.survivors</span><span class="p">,</span> <span class="s1">' | '</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">clan_feuds</span> <span class="n">f</span> <span class="k">WHERE</span> <span class="n">p.clan</span> <span class="k">IN</span> <span class="p">(</span><span class="n">f.clan_a</span><span class="p">,</span> <span class="n">f.clan_b</span><span class="p">))</span> <span class="k">AS</span> <span class="n">clan_feuds</span>
<span class="k">FROM</span> <span class="n">persons</span> <span class="n">p</span> <span class="k">WHERE</span> <span class="n">p.name</span> <span class="k">ILIKE</span> <span class="s1">'%Volnoth%'</span>
</code></pre></div></div>

<table class="result">
<tr><th>name</th><th>affiliation</th><th>clan</th><th>born</th><th>died</th><th>age_at_death</th><th>images</th><th>clan_feuds</th></tr>
<tr><td>Volnoth</td><td>Gatherer</td><td>Lornack</td><td>2264-03-14</td><td>2366-07-24</td><td>102</td><td>0</td><td>Tralesta vs Lornack (2086-2286): Tralesta clan massacred by the Lor…</td></tr>
</table>

<p><em>Not what the script says: Gives the birth date and clan Lornack, plus the death and clan history; the dialogue’s point is that the Acamarian database holds only the birth record.</em></p>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>BEVERLY:</strong> I’ve been digging through the medical database from Acamar Three for hours and I’ve found another victim of the microvirus that killed Volnoth. But just one.</p>

  <p><strong>BEVERLY:</strong> Fifty-three years ago. A Gatherer named Penthor-Mul.</p>
</blockquote>

<p><em>Nobody speaks this request in the script. Claude was asked: “Computer, search the medical database from Acamar Three for any other victims of the microvirus that killed Volnoth.”</em></p>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">m.id</span><span class="p">,</span> <span class="n">p.name</span><span class="p">,</span> <span class="n">p.affiliation</span><span class="p">,</span> <span class="n">p.clan</span><span class="p">,</span> <span class="n">p.born</span><span class="p">,</span> <span class="n">p.died</span><span class="p">,</span>
       <span class="n">m.record_date</span><span class="p">,</span> <span class="n">m.cause_of_death</span><span class="p">,</span> <span class="n">m.pathogen</span><span class="p">,</span> <span class="n">m.facility</span>
<span class="k">FROM</span> <span class="n">medical_records</span> <span class="n">m</span> <span class="k">JOIN</span> <span class="n">persons</span> <span class="n">p</span> <span class="k">ON</span> <span class="n">p.id</span> <span class="o">=</span> <span class="n">m.person_id</span>
<span class="k">WHERE</span> <span class="n">m.pathogen</span> <span class="o">=</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">v.pathogen</span> <span class="k">FROM</span> <span class="n">medical_records</span> <span class="n">v</span>
    <span class="k">JOIN</span> <span class="n">persons</span> <span class="n">vp</span> <span class="k">ON</span> <span class="n">vp.id</span> <span class="o">=</span> <span class="n">v.person_id</span> <span class="k">WHERE</span> <span class="n">vp.name</span> <span class="o">=</span> <span class="s1">'Volnoth'</span><span class="p">)</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">m.record_date</span>
</code></pre></div></div>

<table class="result">
<tr><th>id</th><th>name</th><th>affiliation</th><th>clan</th><th>born</th><th>died</th><th>record_date</th><th>cause_of_death</th><th>pathogen</th><th>facility</th></tr>
<tr><td>157201</td><td>Penthor-Mul</td><td>Gatherer</td><td>Lornack</td><td>NULL</td><td>2313-05-02</td><td>2313-05-02</td><td>heart attack</td><td>Acamarian microvirus</td><td>Acamar III medical database</td></tr>
<tr><td>157202</td><td>Volnoth</td><td>Gatherer</td><td>Lornack</td><td>2264-03-14</td><td>2366-07-24</td><td>2366-07-24</td><td>cardiac arrest</td><td>Acamarian microvirus</td><td>USS Enterprise sickbay</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>RIKER:</strong> Data – got anything in your files on this Penthor-Mul?</p>

  <p><strong>DATA:</strong> Yes. He was captured while leading a Gatherer raid on an Acamarian outpost. He died of a heart attack before his trial ended. Commander, he was a member of the Lornack Clan.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="s1">'person'</span> <span class="k">AS</span> <span class="n">src</span><span class="p">,</span> <span class="n">p.id</span><span class="p">,</span> <span class="n">p.name</span> <span class="k">AS</span> <span class="n">item</span><span class="p">,</span> <span class="n">p.born</span><span class="p">::</span><span class="nb">VARCHAR</span> <span class="k">AS</span> <span class="n">date1</span><span class="p">,</span>
       <span class="n">p.died</span><span class="p">::</span><span class="nb">VARCHAR</span> <span class="k">AS</span> <span class="n">date2</span><span class="p">,</span>
       <span class="n">p.affiliation</span> <span class="o">||</span> <span class="s1">', clan '</span> <span class="o">||</span> <span class="n">p.clan</span> <span class="k">AS</span> <span class="n">detail</span>
<span class="k">FROM</span> <span class="n">persons</span> <span class="n">p</span>
<span class="k">WHERE</span> <span class="n">p.name</span> <span class="k">ILIKE</span> <span class="s1">'%Penthor%'</span>
<span class="nb">UNION</span> <span class="k">ALL</span>
<span class="k">SELECT</span> <span class="s1">'medical'</span><span class="p">,</span> <span class="n">m.id</span><span class="p">,</span> <span class="n">m.cause_of_death</span><span class="p">,</span> <span class="n">m.record_date</span><span class="p">::</span><span class="nb">VARCHAR</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span>
       <span class="n">m.pathogen</span> <span class="o">||</span> <span class="s1">'; '</span> <span class="o">||</span> <span class="n">m.facility</span>
<span class="k">FROM</span> <span class="n">medical_records</span> <span class="n">m</span>
<span class="k">JOIN</span> <span class="n">persons</span> <span class="n">p</span> <span class="k">ON</span> <span class="n">p.id</span> <span class="o">=</span> <span class="n">m.person_id</span>
<span class="k">WHERE</span> <span class="n">p.name</span> <span class="k">ILIKE</span> <span class="s1">'%Penthor%'</span>
<span class="nb">UNION</span> <span class="k">ALL</span>
<span class="k">SELECT</span> <span class="s1">'civil'</span><span class="p">,</span> <span class="n">c.id</span><span class="p">,</span> <span class="n">c.record_type</span><span class="p">,</span> <span class="n">c.record_date</span><span class="p">::</span><span class="nb">VARCHAR</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span>
       <span class="n">c.planet</span> <span class="o">||</span> <span class="s1">': '</span> <span class="o">||</span> <span class="n">c.details</span>
<span class="k">FROM</span> <span class="n">civil_records</span> <span class="n">c</span>
<span class="k">JOIN</span> <span class="n">persons</span> <span class="n">p</span> <span class="k">ON</span> <span class="n">p.id</span> <span class="o">=</span> <span class="n">c.person_id</span>
<span class="k">WHERE</span> <span class="n">p.name</span> <span class="k">ILIKE</span> <span class="s1">'%Penthor%'</span>
<span class="nb">UNION</span> <span class="k">ALL</span>
<span class="k">SELECT</span> <span class="s1">'image'</span><span class="p">,</span> <span class="n">i.id</span><span class="p">,</span> <span class="n">i.caption</span><span class="p">,</span> <span class="n">i.taken</span><span class="p">::</span><span class="nb">VARCHAR</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span>
       <span class="n">i.planet</span> <span class="o">||</span> <span class="s1">'; tagged: '</span> <span class="o">||</span> <span class="nf">array_to_string</span><span class="p">(</span><span class="n">i.people_tagged</span><span class="p">,</span>
       <span class="s1">', '</span><span class="p">)</span>
<span class="k">FROM</span> <span class="n">image_archive</span> <span class="n">i</span>
<span class="k">WHERE</span> <span class="n">i.caption</span> <span class="k">ILIKE</span> <span class="s1">'%Penthor%'</span> <span class="k">OR</span> <span class="nf">array_to_string</span><span class="p">(</span><span class="n">i.people_tagged</span><span class="p">,</span>
       <span class="s1">','</span><span class="p">)</span> <span class="k">ILIKE</span> <span class="s1">'%Penthor%'</span>
<span class="nb">UNION</span> <span class="k">ALL</span>
<span class="k">SELECT</span> <span class="s1">'library'</span><span class="p">,</span> <span class="n">l.entry_id</span><span class="p">,</span> <span class="n">l.term</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="n">l.description</span>
<span class="k">FROM</span> <span class="n">library</span> <span class="n">l</span>
<span class="k">WHERE</span> <span class="n">l.term</span> <span class="k">ILIKE</span> <span class="s1">'%Penthor%'</span> <span class="k">OR</span> <span class="n">l.description</span> <span class="k">ILIKE</span> <span class="s1">'%Penthor%'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">src</span><span class="p">,</span> <span class="n">date1</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 7 rows.</caption>
<tr><th>src</th><th>id</th><th>item</th><th>date1</th><th>date2</th><th>detail</th></tr>
<tr><td>civil</td><td>157103</td><td>arrest</td><td>2313-03-11</td><td>NULL</td><td>Acamar III: Captured while leading a Gatherer raid on an Acamarian …</td></tr>
<tr><td>civil</td><td>157104</td><td>trial</td><td>2313-04-20</td><td>NULL</td><td>Acamar III: Trial opened</td></tr>
<tr><td>civil</td><td>157105</td><td>death</td><td>2313-05-02</td><td>NULL</td><td>Acamar III: Died of a heart attack before his trial ended</td></tr>
<tr><td>image</td><td>157402</td><td>Gatherer raid leader Penthor-Mul in custody at the outpost</td><td>2313-03-11</td><td>NULL</td><td>Acamar III; tagged: Penthor-Mul</td></tr>
<tr><td>image</td><td>157401</td><td>Penthor-Mul being led from his trial</td><td>2313-04-27</td><td>NULL</td><td>Acamar III; tagged: Penthor-Mul</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>RIKER:</strong> Display Volnoth’s birth record again.</p>

  <p><strong>BEVERLY:</strong> Lornack… the same clan….</p>

  <p><strong>RIKER:</strong> The only two recorded deaths from this microvirus… members of the same clan… what does that tell us, Doctor?</p>

  <p><strong>BEVERLY:</strong> If these microbes were engineered for murder, I’d say somebody’s going after the whole family.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">p.name</span><span class="p">,</span> <span class="n">p.affiliation</span><span class="p">,</span> <span class="n">p.clan</span><span class="p">,</span> <span class="n">p.born</span><span class="p">,</span> <span class="n">c.record_type</span><span class="p">,</span>
       <span class="n">c.record_date</span><span class="p">,</span> <span class="n">c.planet</span><span class="p">,</span> <span class="n">c.details</span>
<span class="k">FROM</span> <span class="n">persons</span> <span class="n">p</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">civil_records</span> <span class="n">c</span> <span class="k">ON</span> <span class="n">c.person_id</span> <span class="o">=</span> <span class="n">p.id</span>
  <span class="k">AND</span> <span class="n">c.record_type</span> <span class="k">ILIKE</span> <span class="s1">'%birth%'</span>
<span class="k">WHERE</span> <span class="n">p.name</span> <span class="o">=</span> <span class="s1">'Volnoth'</span>
</code></pre></div></div>

<table class="result">
<tr><th>name</th><th>affiliation</th><th>clan</th><th>born</th><th>record_type</th><th>record_date</th><th>planet</th><th>details</th></tr>
<tr><td>Volnoth</td><td>Gatherer</td><td>Lornack</td><td>2264-03-14</td><td>birth</td><td>2264-03-14</td><td>Acamar III</td><td>Born to the clan Lornack</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>DATA:</strong> Commander, Chorgan, the present leader of the Gatherers, is also from the Lornack clan.</p>
</blockquote>

<p><em>Nobody speaks this request in the script. Claude was asked: “Data, is anyone else from the Lornack clan still alive?”</em></p>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">p.id</span><span class="p">,</span> <span class="n">p.name</span><span class="p">,</span> <span class="n">p.affiliation</span><span class="p">,</span> <span class="n">p.clan</span><span class="p">,</span> <span class="n">p.born</span><span class="p">,</span> <span class="n">p.died</span>
<span class="k">FROM</span> <span class="n">persons</span> <span class="n">p</span>
<span class="k">WHERE</span> <span class="n">p.clan</span> <span class="o">=</span> <span class="s1">'Lornack'</span> <span class="k">AND</span> <span class="n">p.died</span> <span class="k">IS</span> <span class="nb">NULL</span>
  <span class="k">AND</span> <span class="k">NOT</span> <span class="k">EXISTS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="mi">1</span> <span class="k">FROM</span> <span class="n">civil_records</span> <span class="n">c</span> <span class="k">WHERE</span> <span class="n">c.person_id</span> <span class="o">=</span> <span class="n">p.id</span>
    <span class="k">AND</span> <span class="n">c.record_type</span> <span class="o">=</span> <span class="s1">'death'</span><span class="p">)</span>
  <span class="k">AND</span> <span class="k">NOT</span> <span class="k">EXISTS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="mi">1</span> <span class="k">FROM</span> <span class="n">medical_records</span> <span class="n">m</span>
      <span class="k">WHERE</span> <span class="n">m.person_id</span> <span class="o">=</span> <span class="n">p.id</span> <span class="k">AND</span> <span class="n">m.cause_of_death</span> <span class="k">IS</span> <span class="k">NOT</span> <span class="nb">NULL</span><span class="p">)</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">p.born</span>
</code></pre></div></div>

<table class="result">
<tr><th>id</th><th>name</th><th>affiliation</th><th>clan</th><th>born</th><th>died</th></tr>
<tr><td>157003</td><td>Chorgan</td><td>Gatherer</td><td>Lornack</td><td>NULL</td><td>NULL</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>RIKER:</strong> I want to know just how this clan was involved in the Acamarian blood feuds… any clues to their enemies you can find…</p>

  <p><strong>DATA:</strong> Sir, eighty years ago, the Lornacks massacred a rival clan, the Tralestas. It ended a feud that had lasted for two hundred years.</p>

  <p><strong>RIKER:</strong> Ended it?</p>

  <p><strong>DATA:</strong> According to these records, there were no survivors. The Tralesta clan was annihilated.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">f.id</span><span class="p">,</span> <span class="n">f.planet</span><span class="p">,</span> <span class="n">f.clan_a</span><span class="p">,</span> <span class="n">f.clan_b</span><span class="p">,</span> <span class="n">f.started</span><span class="p">,</span> <span class="n">f.ended</span><span class="p">,</span>
       <span class="n">f.ended</span> <span class="o">-</span> <span class="n">f.started</span> <span class="k">AS</span> <span class="n">years</span><span class="p">,</span> <span class="n">f.outcome</span><span class="p">,</span> <span class="n">f.survivors</span><span class="p">,</span>
  <span class="k">CASE</span> <span class="k">WHEN</span> <span class="n">f.clan_a</span> <span class="o">=</span> <span class="s1">'Lornack'</span> <span class="k">THEN</span> <span class="n">f.clan_b</span> <span class="k">ELSE</span> <span class="n">f.clan_a</span> <span class="k">END</span> <span class="k">AS</span> <span class="n">enemy_clan</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">persons</span> <span class="n">p</span>
      <span class="k">WHERE</span> <span class="n">p.clan</span> <span class="o">=</span> <span class="k">CASE</span> <span class="k">WHEN</span> <span class="n">f.clan_a</span> <span class="o">=</span> <span class="s1">'Lornack'</span> <span class="k">THEN</span> <span class="n">f.clan_b</span> <span class="k">ELSE</span> <span class="n">f.clan_a</span> <span class="k">END</span><span class="p">)</span> <span class="k">AS</span> <span class="n">enemy_persons_on_file</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">string_agg</span><span class="p">(</span><span class="n">p.name</span> <span class="o">||</span> <span class="s1">' ('</span> <span class="o">||</span> <span class="nf">coalesce</span><span class="p">(</span><span class="n">p.affiliation</span><span class="p">,</span><span class="s1">'?'</span><span class="p">)</span> <span class="o">||</span> <span class="s1">', born '</span> <span class="o">||</span> <span class="nf">coalesce</span><span class="p">(</span><span class="n">p.born</span><span class="p">::</span><span class="nb">VARCHAR</span><span class="p">,</span><span class="s1">'?'</span><span class="p">)</span> <span class="o">||</span> <span class="s1">', died '</span> <span class="o">||</span> <span class="nf">coalesce</span><span class="p">(</span><span class="n">p.died</span><span class="p">::</span><span class="nb">VARCHAR</span><span class="p">,</span><span class="s1">'no record'</span><span class="p">)</span> <span class="o">||</span> <span class="s1">')'</span><span class="p">,</span> <span class="s1">'; '</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">persons</span> <span class="n">p</span> <span class="k">WHERE</span> <span class="n">p.clan</span> <span class="o">=</span> <span class="k">CASE</span> <span class="k">WHEN</span> <span class="n">f.clan_a</span> <span class="o">=</span> <span class="s1">'Lornack'</span> <span class="k">THEN</span> <span class="n">f.clan_b</span> <span class="k">ELSE</span> <span class="n">f.clan_a</span> <span class="k">END</span><span class="p">)</span> <span class="k">AS</span> <span class="n">enemy_persons</span>
<span class="k">FROM</span> <span class="n">clan_feuds</span> <span class="n">f</span>
<span class="k">WHERE</span> <span class="s1">'Lornack'</span> <span class="k">IN</span> <span class="p">(</span><span class="n">f.clan_a</span><span class="p">,</span> <span class="n">f.clan_b</span><span class="p">)</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">f.started</span>
</code></pre></div></div>

<table class="result">
<tr><th>id</th><th>planet</th><th>clan_a</th><th>clan_b</th><th>started</th><th>ended</th><th>years</th><th>outcome</th><th>survivors</th><th>enemy_clan</th><th>enemy_persons_on_file</th><th>enemy_persons</th></tr>
<tr><td>157301</td><td>Acamar III</td><td>Tralesta</td><td>Lornack</td><td>2086</td><td>2286</td><td>200</td><td>Tralesta clan massacred by the Lornacks</td><td>0</td><td>Tralesta</td><td>3</td><td>Hesra (Acamarian, born 2231-07-19, died 2286-10-05); Dovan (Acamari…</td></tr>
<tr><td>157302</td><td>Acamar III</td><td>Lornack</td><td>Dovrak</td><td>2170</td><td>2231</td><td>61</td><td>truce</td><td>NULL</td><td>Dovrak</td><td>2</td><td>Nessa (Acamarian, born 2322-11-30, died no record); Orlen (Acamaria…</td></tr>
</table>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">entry_id</span><span class="p">,</span> <span class="n">term</span><span class="p">,</span> <span class="n">category</span><span class="p">,</span> <span class="n">database_name</span><span class="p">,</span> <span class="n">description</span>
<span class="k">FROM</span> <span class="n">library</span>
<span class="k">WHERE</span> <span class="n">description</span> <span class="k">ILIKE</span> <span class="s1">'%Lornack%'</span> <span class="k">OR</span> <span class="n">term</span> <span class="k">ILIKE</span> <span class="s1">'%Lornack%'</span> <span class="k">OR</span> <span class="n">description</span> <span class="k">ILIKE</span> <span class="s1">'%Tralesta%'</span> <span class="k">OR</span> <span class="n">term</span> <span class="k">ILIKE</span> <span class="s1">'%Tralesta%'</span> <span class="k">OR</span> <span class="n">term</span> <span class="k">ILIKE</span> <span class="s1">'%blood feud%'</span>
</code></pre></div></div>

<table class="result">
<caption>No rows.</caption>
<tr><th>entry_id</th><th>term</th><th>category</th><th>database_name</th><th>description</th></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>BEVERLY:</strong> Computer, any members of the Acamarian delegation in the Tralesta clan?</p>

  <p><strong>COMPUTER:</strong> Clan affiliation is not within provided records.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">pa.name</span><span class="p">,</span> <span class="n">pa.role</span><span class="p">,</span> <span class="nf">count</span><span class="p">(</span><span class="n">p.id</span><span class="p">)</span> <span class="k">AS</span> <span class="n">person_records</span><span class="p">,</span>
       <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">p.clan</span> <span class="o">=</span> <span class="s1">'Tralesta'</span><span class="p">)</span> <span class="k">AS</span> <span class="n">tralesta_records</span><span class="p">,</span>
       <span class="nf">string_agg</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">p.clan</span><span class="p">,</span> <span class="s1">', '</span><span class="p">)</span> <span class="k">AS</span> <span class="n">clans_on_file</span>
<span class="k">FROM</span> <span class="n">passengers</span> <span class="n">pa</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">persons</span> <span class="n">p</span> <span class="k">ON</span> <span class="n">pa.name</span> <span class="k">IS</span> <span class="k">NOT</span> <span class="nb">NULL</span>
  <span class="k">AND</span> <span class="p">(</span><span class="n">p.name</span> <span class="k">ILIKE</span> <span class="s1">'%'</span> <span class="o">||</span> <span class="n">pa.name</span> <span class="o">||</span> <span class="s1">'%'</span> <span class="k">OR</span> <span class="n">pa.name</span> <span class="k">ILIKE</span> <span class="s1">'%'</span> <span class="o">||</span> <span class="n">p.name</span> <span class="o">||</span> <span class="s1">'%'</span><span class="p">)</span>
<span class="k">WHERE</span> <span class="n">pa.delegation</span> <span class="o">=</span> <span class="s1">'Acamarian'</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">pa.id</span><span class="p">,</span> <span class="n">pa.name</span><span class="p">,</span> <span class="n">pa.role</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">pa.id</span>
</code></pre></div></div>

<table class="result">
<tr><th>name</th><th>role</th><th>person_records</th><th>tralesta_records</th><th>clans_on_file</th></tr>
<tr><td>Marouk</td><td>Sovereign of Acamar III</td><td>1</td><td>0</td><td>NULL</td></tr>
<tr><td>Yuta</td><td>servant: cook and food taster</td><td>0</td><td>0</td><td>NULL</td></tr>
<tr><td>NULL</td><td>bodyguard</td><td>0</td><td>0</td><td>NULL</td></tr>
<tr><td>NULL</td><td>servant</td><td>0</td><td>0</td><td>NULL</td></tr>
<tr><td>NULL</td><td>servant</td><td>0</td><td>0</td><td>NULL</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>RIKER:</strong> There’s got to be a missing link here…</p>

  <p><strong>DATA:</strong> Commander, I believe I have found a correlation between the two deaths… your “missing link” …</p>

  <p><strong>DATA:</strong> That is Penthor-Mul being led from his trial.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">i.id</span><span class="p">,</span> <span class="n">i.planet</span><span class="p">,</span> <span class="n">i.taken</span><span class="p">,</span> <span class="n">i.caption</span><span class="p">,</span> <span class="n">i.people_tagged</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">string_agg</span><span class="p">(</span><span class="n">pa.name</span> <span class="o">||</span> <span class="s1">' ('</span> <span class="o">||</span> <span class="n">pa.role</span> <span class="o">||</span> <span class="s1">')'</span><span class="p">,</span> <span class="s1">', '</span><span class="p">)</span>
      <span class="k">FROM</span> <span class="n">passengers</span> <span class="n">pa</span> <span class="k">WHERE</span> <span class="n">pa.delegation</span> <span class="o">=</span> <span class="s1">'Acamarian'</span>
    <span class="k">AND</span> <span class="nf">list_contains</span><span class="p">(</span><span class="n">i.people_tagged</span><span class="p">,</span>
         <span class="n">pa.name</span><span class="p">))</span> <span class="k">AS</span> <span class="n">delegation_members_present</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">string_agg</span><span class="p">(</span><span class="n">p.name</span> <span class="o">||</span> <span class="s1">' ['</span> <span class="o">||</span> <span class="n">p.clan</span> <span class="o">||</span> <span class="s1">', died '</span> <span class="o">||</span> <span class="nf">coalesce</span><span class="p">(</span><span class="n">p.died</span><span class="p">::</span><span class="nb">VARCHAR</span><span class="p">,</span><span class="s1">'-'</span><span class="p">)</span> <span class="o">||</span> <span class="s1">']'</span><span class="p">,</span> <span class="s1">', '</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">persons</span> <span class="n">p</span> <span class="k">WHERE</span> <span class="n">p.clan</span> <span class="k">IS</span> <span class="k">NOT</span> <span class="nb">NULL</span> <span class="k">AND</span> <span class="nf">list_contains</span><span class="p">(</span><span class="n">i.people_tagged</span><span class="p">,</span> <span class="n">p.name</span><span class="p">))</span> <span class="k">AS</span> <span class="n">clan_members_present</span>
<span class="k">FROM</span> <span class="n">image_archive</span> <span class="n">i</span>
<span class="k">WHERE</span> <span class="n">i.planet</span> <span class="k">ILIKE</span> <span class="s1">'Acamar%'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">i.taken</span>
</code></pre></div></div>

<table class="result">
<tr><th>id</th><th>planet</th><th>taken</th><th>caption</th><th>people_tagged</th><th>delegation_members_present</th><th>clan_members_present</th></tr>
<tr><td>157402</td><td>Acamar III</td><td>2313-03-11</td><td>Gatherer raid leader Penthor-Mul in custody at the outpost</td><td>[Penthor-Mul]</td><td>NULL</td><td>Penthor-Mul [Lornack, died 2313-05-02]</td></tr>
<tr><td>157404</td><td>Acamar III</td><td>2313-04-20</td><td>Crowd outside the courthouse as a Gatherer trial opens</td><td>[]</td><td>NULL</td><td>NULL</td></tr>
<tr><td>157401</td><td>Acamar III</td><td>2313-04-27</td><td>Penthor-Mul being led from his trial</td><td>[Penthor-Mul]</td><td>NULL</td><td>Penthor-Mul [Lornack, died 2313-05-02]</td></tr>
<tr><td>157405</td><td>Acamar III</td><td>2344-06-01</td><td>Clan elders of the Dovrak at the harvest assembly</td><td>[Orlen, Nessa]</td><td>NULL</td><td>Nessa [Dovrak, died -], Orlen [Dovrak, died 2344-09-12]</td></tr>
<tr><td>157403</td><td>Acamar III</td><td>2349-03-02</td><td>Opening day of the trial of the Gatherer Tavik-Dar</td><td>[Tavik-Dar]</td><td>NULL</td><td>Tavik-Dar [Ramsar, died 2349-04-21]</td></tr>
</table>

<p><em>Not what the script says: Reports that no image tags a delegation member and concludes ‘no link found’; it does not offer the image of Penthor-Mul being led from his trial.</em></p>

<h3 id="sins-of-the-father">Sins of the Father</h3>

<p><a href="https://www.st-minutiae.com/resources/scripts/165.txt">Script</a>. Season 3. Captured Romulan logs say Worf’s father betrayed the Khitomer outpost. Data and Geordi check them against a second source.</p>

<figure class="image"><img src="/images/blog/star-trek/enterprise-computer/sins_of_the_father.jpg" alt="Data, La Forge and Riker compare the Klingon data file with the Intrepid’s sensor log." class="center" width="480" /><figcaption>Data, La Forge and Riker compare the Klingon data file with the Intrepid’s sensor log. <em>Star Trek: The Next Generation</em>, “Sins of the Father” (1990). © CBS Studios Inc.</figcaption></figure>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>PICARD:</strong> Mister Data… I want you to find out everything you can about the destruction of the Khitomer outpost. Cross reference with Romulan tactics and strategic information on the region. Request access to the Klingon central information net.</p>

  <p><strong>DATA:</strong> Commander, I have discovered the basis of the charges against Worf’s father.</p>

  <p><strong>DATA:</strong> Apparently the Klingons recently captured a Romulan ship with logs that provided new information on the Khitomer attack. They clearly indicate a transmission from the outpost to the Romulans moments before the shields dropped.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">WITH</span> <span class="n">r</span> <span class="k">AS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">seq</span><span class="p">,</span> <span class="n">ts</span><span class="p">,</span> <span class="nf">row_number</span><span class="p">()</span> <span class="k">OVER</span> <span class="p">(</span><span class="k">ORDER</span> <span class="k">BY</span> <span class="n">ts</span><span class="p">)</span> <span class="k">AS</span> <span class="n">n</span>
    <span class="k">FROM</span> <span class="n">romulan_logs</span> <span class="k">WHERE</span> <span class="n">signal_type</span> <span class="o">=</span> <span class="s1">'distress signal'</span>
  <span class="k">AND</span> <span class="n">source</span> <span class="o">=</span> <span class="s1">'Khitomer outpost'</span><span class="p">),</span>
     <span class="n">i</span> <span class="k">AS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">seq</span><span class="p">,</span> <span class="n">ts</span><span class="p">,</span> <span class="nf">row_number</span><span class="p">()</span> <span class="k">OVER</span> <span class="p">(</span><span class="k">ORDER</span> <span class="k">BY</span> <span class="n">ts</span><span class="p">)</span> <span class="k">AS</span> <span class="n">n</span>
         <span class="k">FROM</span> <span class="n">sensor_logs</span> <span class="k">WHERE</span> <span class="n">ship_name</span> <span class="o">=</span> <span class="s1">'USS Intrepid'</span>
       <span class="k">AND</span> <span class="n">signal_type</span> <span class="o">=</span> <span class="s1">'distress signal'</span>
       <span class="k">AND</span> <span class="n">source</span> <span class="o">=</span> <span class="s1">'Khitomer outpost'</span><span class="p">)</span>
<span class="k">SELECT</span> <span class="n">i.n</span> <span class="k">AS</span> <span class="n">signal_no</span><span class="p">,</span> <span class="n">i.seq</span> <span class="k">AS</span> <span class="n">intrepid_seq</span><span class="p">,</span> <span class="n">i.ts</span> <span class="k">AS</span> <span class="n">intrepid_ts</span><span class="p">,</span>
       <span class="n">r.seq</span> <span class="k">AS</span> <span class="n">romulan_seq</span><span class="p">,</span> <span class="n">r.ts</span> <span class="k">AS</span> <span class="n">romulan_ts</span><span class="p">,</span>
       <span class="n">r.ts</span> <span class="o">-</span> <span class="n">i.ts</span> <span class="k">AS</span> <span class="n">romulan_offset</span>
<span class="k">FROM</span> <span class="n">i</span> <span class="k">FULL</span> <span class="k">JOIN</span> <span class="n">r</span> <span class="k">USING</span> <span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">n</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 14 rows.</caption>
<tr><th>signal_no</th><th>intrepid_seq</th><th>intrepid_ts</th><th>romulan_seq</th><th>romulan_ts</th><th>romulan_offset</th></tr>
<tr><td>1</td><td>1</td><td>2346-08-19 03:12:04</td><td>3</td><td>2346-08-19 03:12:04</td><td>00:00:00</td></tr>
<tr><td>2</td><td>2</td><td>2346-08-19 03:12:19</td><td>4</td><td>2346-08-19 03:12:19</td><td>00:00:00</td></tr>
<tr><td>3</td><td>3</td><td>2346-08-19 03:12:31</td><td>5</td><td>2346-08-19 03:12:31</td><td>00:00:00</td></tr>
<tr><td>4</td><td>4</td><td>2346-08-19 03:12:47</td><td>6</td><td>2346-08-19 03:12:47</td><td>00:00:00</td></tr>
<tr><td>5</td><td>5</td><td>2346-08-19 03:13:02</td><td>7</td><td>2346-08-19 03:13:02</td><td>00:00:00</td></tr>
</table>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">l.seq</span><span class="p">,</span> <span class="n">l.ts</span><span class="p">,</span> <span class="n">l.signal_type</span><span class="p">,</span> <span class="n">l.source</span><span class="p">,</span> <span class="n">l.security_code</span><span class="p">,</span>
       <span class="n">p.name</span> <span class="k">AS</span> <span class="n">code_holder</span><span class="p">,</span> <span class="n">p.post</span>
<span class="k">FROM</span> <span class="n">romulan_logs</span> <span class="n">l</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">personnel</span> <span class="n">p</span> <span class="k">ON</span> <span class="n">p.security_code</span> <span class="o">=</span> <span class="n">l.security_code</span>
<span class="k">WHERE</span> <span class="n">l.signal_type</span> <span class="o">&lt;&gt;</span> <span class="s1">'distress signal'</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">l.seq</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 10 rows.</caption>
<tr><th>seq</th><th>ts</th><th>signal_type</th><th>source</th><th>security_code</th><th>code_holder</th><th>post</th></tr>
<tr><td>1</td><td>2346-08-19 02:40:00</td><td>transmission</td><td>Khitomer outpost</td><td>KDF-1-0012-QOR</td><td>NULL</td><td>Khitomer outpost commander</td></tr>
<tr><td>2</td><td>2346-08-19 03:11:52</td><td>transmission</td><td>Romulan patrol ship</td><td>NULL</td><td>NULL</td><td>NULL</td></tr>
<tr><td>11</td><td>2346-08-19 03:14:03</td><td>sensor sweep</td><td>Khitomer outpost</td><td>NULL</td><td>NULL</td><td>NULL</td></tr>
<tr><td>12</td><td>2346-08-19 03:14:11</td><td>sensor sweep</td><td>Khitomer outpost</td><td>NULL</td><td>NULL</td><td>NULL</td></tr>
<tr><td>13</td><td>2346-08-19 03:14:19</td><td>subspace handshake</td><td>Khitomer outpost</td><td>KDF-7-2291-TAJ</td><td>Mogh</td><td>Khitomer outpost</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> From Worf’s father?</p>

  <p><strong>DATA:</strong> It does correspond to Mogh’s personal security code.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">l.seq</span><span class="p">,</span> <span class="n">l.ts</span><span class="p">,</span> <span class="n">l.signal_type</span><span class="p">,</span> <span class="n">l.source</span><span class="p">,</span> <span class="n">l.security_code</span><span class="p">,</span>
       <span class="n">p.name</span> <span class="k">AS</span> <span class="n">code_holder</span><span class="p">,</span> <span class="n">p.species</span><span class="p">,</span> <span class="n">p.post</span><span class="p">,</span>
  <span class="k">EXISTS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="mi">1</span> <span class="k">FROM</span> <span class="n">sensor_logs</span> <span class="n">s</span>
      <span class="k">WHERE</span> <span class="n">s.signal_type</span> <span class="o">=</span> <span class="n">l.signal_type</span> <span class="k">AND</span> <span class="n">s.source</span> <span class="o">=</span> <span class="n">l.source</span>
    <span class="k">AND</span> <span class="n">s.ts</span> <span class="k">BETWEEN</span> <span class="n">l.ts</span> <span class="o">-</span> <span class="nb">INTERVAL</span> <span class="mi">3</span> <span class="k">SECOND</span>
    <span class="k">AND</span> <span class="n">l.ts</span> <span class="o">+</span> <span class="nb">INTERVAL</span> <span class="mi">3</span> <span class="k">SECOND</span><span class="p">)</span> <span class="k">AS</span> <span class="n">seen_by_starfleet_sensors</span>
<span class="k">FROM</span> <span class="n">romulan_logs</span> <span class="n">l</span>
<span class="k">JOIN</span> <span class="n">personnel</span> <span class="n">p</span> <span class="k">ON</span> <span class="n">p.security_code</span> <span class="o">=</span> <span class="n">l.security_code</span>
<span class="k">WHERE</span> <span class="n">p.name</span> <span class="o">=</span> <span class="s1">'Mogh'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">l.seq</span>
</code></pre></div></div>

<table class="result">
<tr><th>seq</th><th>ts</th><th>signal_type</th><th>source</th><th>security_code</th><th>code_holder</th><th>species</th><th>post</th><th>seen_by_starfleet_sensors</th></tr>
<tr><td>13</td><td>2346-08-19 03:14:19</td><td>subspace handshake</td><td>Khitomer outpost</td><td>KDF-7-2291-TAJ</td><td>Mogh</td><td>Klingon</td><td>Khitomer outpost</td><td>false</td></tr>
<tr><td>14</td><td>2346-08-19 03:14:20</td><td>transmission</td><td>Khitomer outpost</td><td>KDF-7-2291-TAJ</td><td>Mogh</td><td>Klingon</td><td>Khitomer outpost</td><td>false</td></tr>
<tr><td>15</td><td>2346-08-19 03:14:24</td><td>transmission</td><td>Romulan patrol ship</td><td>KDF-7-2291-TAJ</td><td>Mogh</td><td>Klingon</td><td>Khitomer outpost</td><td>false</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>RIKER:</strong> How can we be sure these records haven’t been falsified?</p>

  <p><strong>GEORDI:</strong> We can cross check them against the Intrepid’s sensor logs…</p>

  <p><strong>DATA:</strong> Both the Intrepid and Romulan logs show a series of distress signals from Khitomer…</p>

  <p><strong>GEORDI:</strong> Gaps in the Intrepid logs, missing information because of the range…</p>

  <p><strong>DATA:</strong> This is where Mogh’s alleged transmission should be.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">WITH</span> <span class="n">r</span> <span class="k">AS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">seq</span><span class="p">,</span> <span class="n">ts</span><span class="p">,</span> <span class="nf">row_number</span><span class="p">()</span> <span class="k">OVER</span> <span class="p">(</span><span class="k">ORDER</span> <span class="k">BY</span> <span class="n">ts</span><span class="p">)</span> <span class="k">AS</span> <span class="n">n</span>
    <span class="k">FROM</span> <span class="n">romulan_logs</span> <span class="k">WHERE</span> <span class="n">signal_type</span> <span class="o">=</span> <span class="s1">'distress signal'</span>
  <span class="k">AND</span> <span class="n">source</span> <span class="o">=</span> <span class="s1">'Khitomer outpost'</span><span class="p">),</span>
     <span class="n">i</span> <span class="k">AS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">seq</span><span class="p">,</span> <span class="n">ts</span><span class="p">,</span> <span class="nf">row_number</span><span class="p">()</span> <span class="k">OVER</span> <span class="p">(</span><span class="k">ORDER</span> <span class="k">BY</span> <span class="n">ts</span><span class="p">)</span> <span class="k">AS</span> <span class="n">n</span>
         <span class="k">FROM</span> <span class="n">sensor_logs</span> <span class="k">WHERE</span> <span class="n">ship_name</span> <span class="o">=</span> <span class="s1">'USS Intrepid'</span>
       <span class="k">AND</span> <span class="n">signal_type</span> <span class="o">=</span> <span class="s1">'distress signal'</span>
       <span class="k">AND</span> <span class="n">source</span> <span class="o">=</span> <span class="s1">'Khitomer outpost'</span><span class="p">),</span>
     <span class="n">x</span> <span class="k">AS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">n</span><span class="p">,</span> <span class="n">i.ts</span> <span class="k">AS</span> <span class="n">intrepid_ts</span><span class="p">,</span> <span class="n">r.ts</span> <span class="k">AS</span> <span class="n">romulan_ts</span><span class="p">,</span>
            <span class="n">r.seq</span> <span class="k">AS</span> <span class="n">romulan_seq</span><span class="p">,</span>
            <span class="nf">epoch</span><span class="p">(</span><span class="n">r.ts</span> <span class="o">-</span> <span class="n">i.ts</span><span class="p">)</span> <span class="k">AS</span> <span class="n">offset_s</span> <span class="k">FROM</span> <span class="n">i</span> <span class="k">FULL</span> <span class="k">JOIN</span> <span class="n">r</span> <span class="k">USING</span> <span class="p">(</span><span class="n">n</span><span class="p">))</span>
<span class="k">SELECT</span> <span class="n">offset_s</span> <span class="k">AS</span> <span class="n">romulan_minus_intrepid_seconds</span><span class="p">,</span>
       <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="n">distress_signals</span><span class="p">,</span> <span class="nf">min</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">AS</span> <span class="n">first_signal</span><span class="p">,</span>
       <span class="nf">max</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">AS</span> <span class="n">last_signal</span><span class="p">,</span>
  <span class="nf">min</span><span class="p">(</span><span class="n">intrepid_ts</span><span class="p">)</span> <span class="k">AS</span> <span class="n">intrepid_from</span><span class="p">,</span> <span class="nf">max</span><span class="p">(</span><span class="n">intrepid_ts</span><span class="p">)</span> <span class="k">AS</span> <span class="n">intrepid_to</span><span class="p">,</span>
         <span class="nf">min</span><span class="p">(</span><span class="n">romulan_seq</span><span class="p">)</span> <span class="k">AS</span> <span class="n">romulan_seq_from</span><span class="p">,</span>
         <span class="nf">max</span><span class="p">(</span><span class="n">romulan_seq</span><span class="p">)</span> <span class="k">AS</span> <span class="n">romulan_seq_to</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">romulan_logs</span> <span class="n">l</span> <span class="k">WHERE</span> <span class="n">l.security_code</span> <span class="k">IS</span> <span class="k">NOT</span> <span class="nb">NULL</span>
    <span class="k">AND</span> <span class="n">l.seq</span> <span class="o">&gt;</span> <span class="p">(</span><span class="k">SELECT</span> <span class="nf">max</span><span class="p">(</span><span class="n">romulan_seq</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">x</span> <span class="n">x2</span>
      <span class="k">WHERE</span> <span class="n">x2.offset_s</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> <span class="k">AND</span> <span class="n">l.seq</span> <span class="o">&lt;</span> <span class="p">(</span><span class="k">SELECT</span> <span class="nf">min</span><span class="p">(</span><span class="n">romulan_seq</span><span class="p">)</span>
      <span class="k">FROM</span> <span class="n">x</span> <span class="n">x3</span>
      <span class="k">WHERE</span> <span class="n">x3.offset_s</span> <span class="o">&lt;&gt;</span> <span class="mi">0</span><span class="p">))</span> <span class="k">AS</span> <span class="n">coded_entries_between_segments</span>
<span class="k">FROM</span> <span class="n">x</span> <span class="k">GROUP</span> <span class="k">BY</span> <span class="n">offset_s</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">first_signal</span>
</code></pre></div></div>

<table class="result">
<tr><th>romulan_minus_intrepid_seconds</th><th>distress_signals</th><th>first_signal</th><th>last_signal</th><th>intrepid_from</th><th>intrepid_to</th><th>romulan_seq_from</th><th>romulan_seq_to</th><th>coded_entries_between_segments</th></tr>
<tr><td>0.0</td><td>8</td><td>1</td><td>8</td><td>2346-08-19 03:12:04</td><td>2346-08-19 03:13:49</td><td>3</td><td>10</td><td>3</td></tr>
<tr><td>2.5</td><td>6</td><td>9</td><td>14</td><td>2346-08-19 03:14:41</td><td>2346-08-19 03:15:51</td><td>19</td><td>24</td><td>3</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Wait a second, Data. Back up.</p>

  <p><strong>GEORDI:</strong> Look at this… just before the Intrepid gap begins, the timebase of both files are in perfect sync… but look at the signals just after the shields dropped.</p>

  <p><strong>DATA:</strong> They are no longer synchronous.</p>

  <p><strong>GEORDI:</strong> Commander, somebody’s been rewriting history.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">WITH</span> <span class="n">drop_t</span> <span class="k">AS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">ts</span> <span class="k">FROM</span> <span class="n">romulan_logs</span>
    <span class="k">WHERE</span> <span class="n">signal_type</span> <span class="o">=</span> <span class="s1">'shield collapse'</span><span class="p">),</span>
<span class="n">r</span> <span class="k">AS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">seq</span><span class="p">,</span> <span class="n">ts</span><span class="p">,</span> <span class="n">signal_type</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span>
       <span class="nf">row_number</span><span class="p">()</span> <span class="k">OVER</span> <span class="p">(</span><span class="k">ORDER</span> <span class="k">BY</span> <span class="n">ts</span><span class="p">)</span> <span class="k">AS</span> <span class="n">n</span> <span class="k">FROM</span> <span class="n">romulan_logs</span>
    <span class="k">WHERE</span> <span class="n">ts</span> <span class="o">&gt;</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">ts</span> <span class="k">FROM</span> <span class="n">drop_t</span><span class="p">)),</span>
<span class="n">i</span> <span class="k">AS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">seq</span><span class="p">,</span> <span class="n">ts</span><span class="p">,</span> <span class="n">signal_type</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span>
       <span class="nf">row_number</span><span class="p">()</span> <span class="k">OVER</span> <span class="p">(</span><span class="k">ORDER</span> <span class="k">BY</span> <span class="n">ts</span><span class="p">)</span> <span class="k">AS</span> <span class="n">n</span> <span class="k">FROM</span> <span class="n">sensor_logs</span>
    <span class="k">WHERE</span> <span class="n">ship_name</span> <span class="o">=</span> <span class="s1">'USS Intrepid'</span>
  <span class="k">AND</span> <span class="n">ts</span> <span class="o">&gt;</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">ts</span> <span class="k">FROM</span> <span class="n">drop_t</span><span class="p">)</span> <span class="o">-</span> <span class="nb">INTERVAL</span> <span class="mi">3</span> <span class="k">SECOND</span><span class="p">)</span>
<span class="k">SELECT</span> <span class="n">n</span><span class="p">,</span> <span class="n">i.seq</span> <span class="k">AS</span> <span class="n">intrepid_seq</span><span class="p">,</span> <span class="n">i.ts</span> <span class="k">AS</span> <span class="n">intrepid_ts</span><span class="p">,</span>
       <span class="n">i.signal_type</span> <span class="k">AS</span> <span class="n">intrepid_signal</span><span class="p">,</span> <span class="n">i.source</span> <span class="k">AS</span> <span class="n">intrepid_source</span><span class="p">,</span>
       <span class="n">r.seq</span> <span class="k">AS</span> <span class="n">romulan_seq</span><span class="p">,</span> <span class="n">r.ts</span> <span class="k">AS</span> <span class="n">romulan_ts</span><span class="p">,</span>
              <span class="n">r.signal_type</span> <span class="k">AS</span> <span class="n">romulan_signal</span><span class="p">,</span>
              <span class="nf">epoch</span><span class="p">(</span><span class="n">r.ts</span> <span class="o">-</span> <span class="n">i.ts</span><span class="p">)</span> <span class="k">AS</span> <span class="n">romulan_offset_s</span><span class="p">,</span>
       <span class="nf">epoch</span><span class="p">(</span><span class="n">i.ts</span> <span class="o">-</span> <span class="nf">lag</span><span class="p">(</span><span class="n">i.ts</span><span class="p">)</span> <span class="k">OVER</span> <span class="p">(</span><span class="k">ORDER</span> <span class="k">BY</span> <span class="n">n</span><span class="p">))</span> <span class="k">AS</span> <span class="n">intrepid_interval_s</span><span class="p">,</span>
              <span class="nf">epoch</span><span class="p">(</span><span class="n">r.ts</span> <span class="o">-</span> <span class="nf">lag</span><span class="p">(</span><span class="n">r.ts</span><span class="p">)</span> <span class="k">OVER</span> <span class="p">(</span><span class="k">ORDER</span> <span class="k">BY</span> <span class="n">n</span><span class="p">))</span> <span class="k">AS</span> <span class="n">romulan_interval_s</span>
<span class="k">FROM</span> <span class="n">i</span> <span class="k">FULL</span> <span class="k">JOIN</span> <span class="n">r</span> <span class="k">USING</span> <span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">n</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 8 rows.</caption>
<tr><th>n</th><th>intrepid_seq</th><th>intrepid_ts</th><th>intrepid_signal</th><th>intrepid_source</th><th>romulan_seq</th><th>romulan_ts</th><th>romulan_signal</th><th>romulan_offset_s</th><th>intrepid_interval_s</th><th>romulan_interval_s</th></tr>
<tr><td>1</td><td>9</td><td>2346-08-19 03:14:41</td><td>distress signal</td><td>Khitomer outpost</td><td>19</td><td>2346-08-19 03:14:43.5</td><td>distress signal</td><td>2.5</td><td>NULL</td><td>NULL</td></tr>
<tr><td>2</td><td>10</td><td>2346-08-19 03:14:55</td><td>distress signal</td><td>Khitomer outpost</td><td>20</td><td>2346-08-19 03:14:57.5</td><td>distress signal</td><td>2.5</td><td>14.0</td><td>14.0</td></tr>
<tr><td>3</td><td>11</td><td>2346-08-19 03:15:09</td><td>distress signal</td><td>Khitomer outpost</td><td>21</td><td>2346-08-19 03:15:11.5</td><td>distress signal</td><td>2.5</td><td>14.0</td><td>14.0</td></tr>
<tr><td>4</td><td>12</td><td>2346-08-19 03:15:22</td><td>distress signal</td><td>Khitomer outpost</td><td>22</td><td>2346-08-19 03:15:24.5</td><td>distress signal</td><td>2.5</td><td>13.0</td><td>13.0</td></tr>
<tr><td>5</td><td>13</td><td>2346-08-19 03:15:38</td><td>distress signal</td><td>Khitomer outpost</td><td>23</td><td>2346-08-19 03:15:40.5</td><td>distress signal</td><td>2.5</td><td>16.0</td><td>16.0</td></tr>
</table>

<h3 id="violations">Violations</h3>

<p><a href="https://www.st-minutiae.com/resources/scripts/212.txt">Script</a>. Season 5. Crew members are falling into unexplained comas while a delegation of telepaths is aboard. One investigation in three scenes.</p>

<p><strong>In Engineering: every possible cause</strong></p>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Computer, locate the electropathic pattern described in medical database four-delta-one.</p>

  <p><strong>COMPUTER:</strong> Electropathic pattern located.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">pattern_id</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">database_ref</span> <span class="k">FROM</span> <span class="n">medical_patterns</span>
<span class="k">WHERE</span> <span class="n">database_ref</span> <span class="o">=</span> <span class="s1">'4-delta-1'</span> <span class="k">AND</span> <span class="k">name</span> <span class="o">=</span> <span class="s1">'electropathic pattern'</span>
</code></pre></div></div>

<table class="result">
<tr><th>pattern_id</th><th>name</th><th>database_ref</th></tr>
<tr><td>41</td><td>electropathic pattern</td><td>4-delta-1</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Okay, we’re gonna track down any possible cause of that brain pattern. First, what are the medical conditions that might account for it?</p>

  <p><strong>COMPUTER:</strong> Iresine Syndrome is a cause of the electropathic pattern.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">c.cause_id</span><span class="p">,</span> <span class="n">c.agent</span><span class="p">,</span> <span class="n">c.agent_type</span><span class="p">,</span> <span class="n">c.agent_class</span>
<span class="k">FROM</span> <span class="n">pattern_causes</span> <span class="n">c</span> <span class="k">JOIN</span> <span class="n">medical_patterns</span> <span class="n">p</span> <span class="k">USING</span> <span class="p">(</span><span class="n">pattern_id</span><span class="p">)</span>
<span class="k">WHERE</span> <span class="n">p.name</span> <span class="o">=</span> <span class="s1">'electropathic pattern'</span> <span class="k">AND</span> <span class="n">p.database_ref</span> <span class="o">=</span> <span class="s1">'4-delta-1'</span>
  <span class="k">AND</span> <span class="n">c.agent_type</span> <span class="o">=</span> <span class="s1">'medical'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">c.agent</span>
</code></pre></div></div>

<table class="result">
<tr><th>cause_id</th><th>agent</th><th>agent_type</th><th>agent_class</th></tr>
<tr><td>1</td><td>Iresine Syndrome</td><td>medical</td><td>condition</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Right. And Doctor Crusher’s already eliminated that. How many nonmedical forces or substances might cause the pattern?</p>

  <p><strong>COMPUTER:</strong> There are twenty-two nonmedical agents.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="n">nonmedical_causes</span>
<span class="k">FROM</span> <span class="n">pattern_causes</span> <span class="n">c</span> <span class="k">JOIN</span> <span class="n">medical_patterns</span> <span class="n">p</span> <span class="k">USING</span> <span class="p">(</span><span class="n">pattern_id</span><span class="p">)</span>
<span class="k">WHERE</span> <span class="n">p.name</span> <span class="o">=</span> <span class="s1">'electropathic pattern'</span> <span class="k">AND</span> <span class="n">p.database_ref</span> <span class="o">=</span> <span class="s1">'4-delta-1'</span>
  <span class="k">AND</span> <span class="n">c.agent_type</span> <span class="o">=</span> <span class="s1">'nonmedical'</span>
</code></pre></div></div>

<table class="result">
<tr><th>nonmedical_causes</th></tr>
<tr><td>22</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Okay. And how many of those are present on the Enterprise?</p>

  <p><strong>COMPUTER:</strong> None is present on the Enterprise.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">c.agent</span><span class="p">,</span> <span class="n">c.agent_class</span><span class="p">,</span>
  <span class="k">EXISTS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="mi">1</span> <span class="k">FROM</span> <span class="n">internal_sensor_logs</span> <span class="n">l</span>
      <span class="k">WHERE</span> <span class="n">l.ship</span> <span class="o">=</span> <span class="s1">'Enterprise'</span>
    <span class="k">AND</span> <span class="nf">lower</span><span class="p">(</span><span class="n">l.substance</span><span class="p">)</span> <span class="o">=</span> <span class="nf">lower</span><span class="p">(</span><span class="n">c.agent</span><span class="p">))</span> <span class="k">AS</span> <span class="n">detected_on_enterprise</span><span class="p">,</span>
  <span class="n">s.routinely_scanned</span>
<span class="k">FROM</span> <span class="n">pattern_causes</span> <span class="n">c</span> <span class="k">JOIN</span> <span class="n">medical_patterns</span> <span class="n">p</span> <span class="k">USING</span> <span class="p">(</span><span class="n">pattern_id</span><span class="p">)</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">sensor_scan_config</span> <span class="n">s</span> <span class="k">ON</span> <span class="nf">lower</span><span class="p">(</span><span class="n">s.substance</span><span class="p">)</span> <span class="o">=</span> <span class="nf">lower</span><span class="p">(</span><span class="n">c.agent</span><span class="p">)</span>
<span class="k">WHERE</span> <span class="n">p.name</span> <span class="o">=</span> <span class="s1">'electropathic pattern'</span> <span class="k">AND</span> <span class="n">p.database_ref</span> <span class="o">=</span> <span class="s1">'4-delta-1'</span>
  <span class="k">AND</span> <span class="n">c.agent_type</span> <span class="o">=</span> <span class="s1">'nonmedical'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">c.agent_class</span><span class="p">,</span> <span class="n">c.agent</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 22 rows.</caption>
<tr><th>agent</th><th>agent_class</th><th>detected_on_enterprise</th><th>routinely_scanned</th></tr>
<tr><td>chrysimite</td><td>chemical</td><td>false</td><td>true</td></tr>
<tr><td>dardilion</td><td>chemical</td><td>false</td><td>true</td></tr>
<tr><td>ferrazene</td><td>chemical</td><td>false</td><td>true</td></tr>
<tr><td>hylanatine</td><td>chemical</td><td>false</td><td>true</td></tr>
<tr><td>manzene</td><td>chemical</td><td>false</td><td>true</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Are the ship’s sensors calibrated to detect all those agents?</p>

  <p><strong>COMPUTER:</strong> All agents are scanned by the sensors.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="n">nonmedical_agents</span><span class="p">,</span>
  <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">s.routinely_scanned</span><span class="p">)</span> <span class="k">AS</span> <span class="n">routinely_scanned</span><span class="p">,</span>
  <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">s.routinely_scanned</span> <span class="k">IS</span> <span class="k">NOT</span> <span class="n">TRUE</span><span class="p">)</span> <span class="k">AS</span> <span class="n">not_scanned</span><span class="p">,</span>
  <span class="nf">string_agg</span><span class="p">(</span><span class="n">c.agent</span><span class="p">,</span>
         <span class="s1">', '</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">s.routinely_scanned</span> <span class="k">IS</span> <span class="k">NOT</span> <span class="n">TRUE</span><span class="p">)</span> <span class="k">AS</span> <span class="n">agents_not_scanned</span>
<span class="k">FROM</span> <span class="n">pattern_causes</span> <span class="n">c</span> <span class="k">JOIN</span> <span class="n">medical_patterns</span> <span class="n">p</span> <span class="k">USING</span> <span class="p">(</span><span class="n">pattern_id</span><span class="p">)</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">sensor_scan_config</span> <span class="n">s</span> <span class="k">ON</span> <span class="nf">lower</span><span class="p">(</span><span class="n">s.substance</span><span class="p">)</span> <span class="o">=</span> <span class="nf">lower</span><span class="p">(</span><span class="n">c.agent</span><span class="p">)</span>
<span class="k">WHERE</span> <span class="n">p.name</span> <span class="o">=</span> <span class="s1">'electropathic pattern'</span> <span class="k">AND</span> <span class="n">p.database_ref</span> <span class="o">=</span> <span class="s1">'4-delta-1'</span>
  <span class="k">AND</span> <span class="n">c.agent_type</span> <span class="o">=</span> <span class="s1">'nonmedical'</span>
</code></pre></div></div>

<table class="result">
<tr><th>nonmedical_agents</th><th>routinely_scanned</th><th>not_scanned</th><th>agents_not_scanned</th></tr>
<tr><td>22</td><td>22</td><td>0</td><td>NULL</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Okay. Let’s start with the chemical substances. Name them.</p>

  <p><strong>COMPUTER:</strong> Ferrazene, hylanatine, dardilion, chrysimite, and manzene.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">c.agent</span>
<span class="k">FROM</span> <span class="n">pattern_causes</span> <span class="n">c</span> <span class="k">JOIN</span> <span class="n">medical_patterns</span> <span class="n">p</span> <span class="k">USING</span> <span class="p">(</span><span class="n">pattern_id</span><span class="p">)</span>
<span class="k">WHERE</span> <span class="n">p.name</span> <span class="o">=</span> <span class="s1">'electropathic pattern'</span> <span class="k">AND</span> <span class="n">p.database_ref</span> <span class="o">=</span> <span class="s1">'4-delta-1'</span>
  <span class="k">AND</span> <span class="n">c.agent_type</span> <span class="o">=</span> <span class="s1">'nonmedical'</span> <span class="k">AND</span> <span class="n">c.agent_class</span> <span class="o">=</span> <span class="s1">'chemical'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">c.agent</span>
</code></pre></div></div>

<table class="result">
<tr><th>agent</th></tr>
<tr><td>chrysimite</td></tr>
<tr><td>dardilion</td></tr>
<tr><td>ferrazene</td></tr>
<tr><td>hylanatine</td></tr>
<tr><td>manzene</td></tr>
</table>

<p><em>Not what the script says: The right five chemicals, but in alphabetical order rather than the script’s read-out order.</em></p>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Ferrazene has a complex molecular structure… it breaks down into bilenium and tarrisite. Do the sensors scan for those?</p>

  <p><strong>COMPUTER:</strong> Ship’s sensors scan for both compounds.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">b.compound</span><span class="p">,</span> <span class="n">b.byproduct</span><span class="p">,</span> <span class="n">s.routinely_scanned</span><span class="p">,</span>
  <span class="k">EXISTS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="mi">1</span> <span class="k">FROM</span> <span class="n">internal_sensor_logs</span> <span class="n">l</span>
      <span class="k">WHERE</span> <span class="n">l.ship</span> <span class="o">=</span> <span class="s1">'Enterprise'</span>
    <span class="k">AND</span> <span class="nf">lower</span><span class="p">(</span><span class="n">l.substance</span><span class="p">)</span> <span class="o">=</span> <span class="nf">lower</span><span class="p">(</span><span class="n">b.byproduct</span><span class="p">))</span> <span class="k">AS</span> <span class="n">detected_on_enterprise</span>
<span class="k">FROM</span> <span class="n">compound_byproducts</span> <span class="n">b</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">sensor_scan_config</span> <span class="n">s</span> <span class="k">ON</span> <span class="nf">lower</span><span class="p">(</span><span class="n">s.substance</span><span class="p">)</span> <span class="o">=</span> <span class="nf">lower</span><span class="p">(</span><span class="n">b.byproduct</span><span class="p">)</span>
<span class="k">WHERE</span> <span class="nf">lower</span><span class="p">(</span><span class="n">b.compound</span><span class="p">)</span> <span class="o">=</span> <span class="s1">'ferrazene'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">b.byproduct</span>
</code></pre></div></div>

<table class="result">
<tr><th>compound</th><th>byproduct</th><th>routinely_scanned</th><th>detected_on_enterprise</th></tr>
<tr><td>ferrazene</td><td>bilenium</td><td>true</td><td>false</td></tr>
<tr><td>ferrazene</td><td>tarrisite</td><td>true</td><td>false</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> And are they present on the Enterprise?</p>

  <p><strong>COMPUTER:</strong> Bilenium and tarrisite are not present.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">b.byproduct</span><span class="p">,</span> <span class="nf">count</span><span class="p">(</span><span class="n">l.log_id</span><span class="p">)</span> <span class="k">AS</span> <span class="n">detections_on_enterprise</span>
<span class="k">FROM</span> <span class="n">compound_byproducts</span> <span class="n">b</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">internal_sensor_logs</span> <span class="n">l</span> <span class="k">ON</span> <span class="nf">lower</span><span class="p">(</span><span class="n">l.substance</span><span class="p">)</span> <span class="o">=</span> <span class="nf">lower</span><span class="p">(</span><span class="n">b.byproduct</span><span class="p">)</span> <span class="k">AND</span> <span class="n">l.ship</span> <span class="o">=</span> <span class="s1">'Enterprise'</span>
<span class="k">WHERE</span> <span class="nf">lower</span><span class="p">(</span><span class="n">b.compound</span><span class="p">)</span> <span class="o">=</span> <span class="s1">'ferrazene'</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">b.byproduct</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">b.byproduct</span>
</code></pre></div></div>

<table class="result">
<tr><th>byproduct</th><th>detections_on_enterprise</th></tr>
<tr><td>bilenium</td><td>0</td></tr>
<tr><td>tarrisite</td><td>0</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Do any of the substances break down into by-products that are not scanned for?</p>

  <p><strong>COMPUTER:</strong> Dardilion contains the byproduct nilizene. Sensors do not routinely scan for that substance.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">c.agent</span> <span class="k">AS</span> <span class="n">substance</span><span class="p">,</span> <span class="n">b.byproduct</span><span class="p">,</span> <span class="n">s.routinely_scanned</span>
<span class="k">FROM</span> <span class="n">pattern_causes</span> <span class="n">c</span> <span class="k">JOIN</span> <span class="n">medical_patterns</span> <span class="n">p</span> <span class="k">USING</span> <span class="p">(</span><span class="n">pattern_id</span><span class="p">)</span>
<span class="k">JOIN</span> <span class="n">compound_byproducts</span> <span class="n">b</span> <span class="k">ON</span> <span class="nf">lower</span><span class="p">(</span><span class="n">b.compound</span><span class="p">)</span> <span class="o">=</span> <span class="nf">lower</span><span class="p">(</span><span class="n">c.agent</span><span class="p">)</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">sensor_scan_config</span> <span class="n">s</span> <span class="k">ON</span> <span class="nf">lower</span><span class="p">(</span><span class="n">s.substance</span><span class="p">)</span> <span class="o">=</span> <span class="nf">lower</span><span class="p">(</span><span class="n">b.byproduct</span><span class="p">)</span>
<span class="k">WHERE</span> <span class="n">p.name</span> <span class="o">=</span> <span class="s1">'electropathic pattern'</span> <span class="k">AND</span> <span class="n">p.database_ref</span> <span class="o">=</span> <span class="s1">'4-delta-1'</span>
  <span class="k">AND</span> <span class="n">c.agent_type</span> <span class="o">=</span> <span class="s1">'nonmedical'</span> <span class="k">AND</span> <span class="n">c.agent_class</span> <span class="o">=</span> <span class="s1">'chemical'</span>
  <span class="k">AND</span> <span class="n">s.routinely_scanned</span> <span class="k">IS</span> <span class="k">NOT</span> <span class="n">TRUE</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">c.agent</span><span class="p">,</span> <span class="n">b.byproduct</span>
</code></pre></div></div>

<table class="result">
<tr><th>substance</th><th>byproduct</th><th>routinely_scanned</th></tr>
<tr><td>dardilion</td><td>nilizene</td><td>false</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Well, this isn’t a routine situation. Scan for nilizene.</p>

  <p><strong>COMPUTER:</strong> There is no nilizene on the Enterprise.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">log_id</span><span class="p">,</span> <span class="n">ship</span><span class="p">,</span> <span class="n">location</span><span class="p">,</span> <span class="n">substance</span><span class="p">,</span> <span class="n">stardate</span>
<span class="k">FROM</span> <span class="n">internal_sensor_logs</span> <span class="k">WHERE</span> <span class="nf">lower</span><span class="p">(</span><span class="n">substance</span><span class="p">)</span> <span class="o">=</span> <span class="s1">'nilizene'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">stardate</span><span class="p">,</span> <span class="n">log_id</span>
</code></pre></div></div>

<table class="result">
<tr><th>log_id</th><th>ship</th><th>location</th><th>substance</th><th>stardate</th></tr>
<tr><td>212210</td><td>SS Kallisto</td><td>Cargo Hold 1</td><td>nilizene</td><td>45427.4</td></tr>
</table>

<p><em>Not what the script says: Says it cannot start a scan from records; the logs hold no nilizene reading aboard, but since nilizene is not routinely scanned that does not show the ship is clear. The script’s computer answers ‘There is no nilizene on the Enterprise.’</em></p>

<p><strong>On the bridge: the right query with the wrong filter</strong></p>

<figure class="image"><img src="/images/blog/star-trek/enterprise-computer/violations_bridge.jpg" alt="The search as the episode shows it: “Search parameters: instances of unexplained coma or medical cases diagnosed as Iresine Syndrome during periods when Ullian telepathic historians were present on the planet.”" class="center" width="480" /><figcaption>The search as the episode shows it: “Search parameters: instances of unexplained coma or medical cases diagnosed as Iresine Syndrome during periods when Ullian telepathic historians were present on the planet.” <em>Star Trek: The Next Generation</em>, “Violations” (1992). © CBS Studios Inc.</figcaption></figure>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>PICARD:</strong> Mister Data, I want you to investigate those eleven planets the Ullians have visited. See if there have been any reports of unexplained comas.</p>

  <p><strong>DATA:</strong> Yes, Captain.</p>

  <p><strong>GEORDI:</strong> Well, that’s it for Melina Two. No unexplained comas during the time the Ullians were working there. We’re striking out everywhere.</p>

  <p><strong>DATA:</strong> We have yet to receive transmissions from the two planets of the Nel system. Perhaps they will show different results.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">WITH</span> <span class="n">ullian</span> <span class="k">AS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="k">DISTINCT</span> <span class="n">planet</span> <span class="k">FROM</span> <span class="n">missions</span>
    <span class="k">WHERE</span> <span class="n">delegation</span> <span class="o">=</span> <span class="s1">'Ullian'</span><span class="p">),</span>
<span class="n">reports</span> <span class="k">AS</span> <span class="p">(</span>
  <span class="k">SELECT</span> <span class="s1">'coma incident report'</span> <span class="k">AS</span> <span class="n">source</span><span class="p">,</span> <span class="n">planet</span><span class="p">,</span> <span class="n">stardate</span><span class="p">,</span>
         <span class="nb">NULL</span> <span class="k">AS</span> <span class="n">patient</span><span class="p">,</span> <span class="nb">NULL</span> <span class="k">AS</span> <span class="n">diagnosis</span>
  <span class="k">FROM</span> <span class="n">coma_incidents</span>
  <span class="nb">UNION</span> <span class="k">ALL</span>
  <span class="k">SELECT</span> <span class="s1">'planetary medical record'</span><span class="p">,</span> <span class="n">planet</span><span class="p">,</span> <span class="n">stardate</span><span class="p">,</span> <span class="n">patient</span><span class="p">,</span>
         <span class="nf">coalesce</span><span class="p">(</span><span class="n">diagnosis</span><span class="p">,</span> <span class="s1">'undiagnosed'</span><span class="p">)</span>
  <span class="k">FROM</span> <span class="n">planetary_medical_records</span>
  <span class="k">WHERE</span> <span class="n">condition</span> <span class="o">=</span> <span class="s1">'coma'</span>
<span class="p">)</span>
<span class="k">SELECT</span> <span class="n">r.planet</span><span class="p">,</span> <span class="n">r.stardate</span><span class="p">,</span> <span class="n">r.source</span><span class="p">,</span> <span class="n">r.patient</span><span class="p">,</span> <span class="n">r.diagnosis</span><span class="p">,</span>
  <span class="k">EXISTS</span> <span class="p">(</span><span class="k">SELECT</span> <span class="mi">1</span> <span class="k">FROM</span> <span class="n">missions</span> <span class="n">m</span> <span class="k">WHERE</span> <span class="n">m.delegation</span> <span class="o">=</span> <span class="s1">'Ullian'</span>
    <span class="k">AND</span> <span class="n">m.planet</span> <span class="o">=</span> <span class="n">r.planet</span> <span class="k">AND</span> <span class="n">r.stardate</span> <span class="k">BETWEEN</span> <span class="n">m.arrived_stardate</span>
    <span class="k">AND</span> <span class="n">m.departed_stardate</span><span class="p">)</span> <span class="k">AS</span> <span class="n">during_ullian_visit</span>
<span class="k">FROM</span> <span class="n">reports</span> <span class="n">r</span> <span class="k">JOIN</span> <span class="n">ullian</span> <span class="n">u</span> <span class="k">ON</span> <span class="n">u.planet</span> <span class="o">=</span> <span class="n">r.planet</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">r.planet</span><span class="p">,</span> <span class="n">r.stardate</span><span class="p">,</span> <span class="n">r.source</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 20 rows.</caption>
<tr><th>planet</th><th>stardate</th><th>source</th><th>patient</th><th>diagnosis</th><th>during_ullian_visit</th></tr>
<tr><td>Hurada III</td><td>41194</td><td>planetary medical record</td><td>HUR-1310</td><td>Iresine Syndrome</td><td>false</td></tr>
<tr><td>Hurada III</td><td>43531</td><td>coma incident report</td><td>NULL</td><td>NULL</td><td>true</td></tr>
<tr><td>Hurada III</td><td>43531</td><td>planetary medical record</td><td>HUR-2207</td><td>Iresine Syndrome</td><td>true</td></tr>
<tr><td>Hurada III</td><td>43580</td><td>planetary medical record</td><td>HUR-2215</td><td>cranial trauma</td><td>true</td></tr>
<tr><td>Hurada III</td><td>43657</td><td>coma incident report</td><td>NULL</td><td>NULL</td><td>true</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> We didn’t look into the comas that were explained.</p>

  <p><strong>DATA:</strong> You are checking for instances of Iresine Syndrome…</p>

  <p><strong>GEORDI:</strong> Right… and correlating them with visits by the Ullians – and there we are.</p>

  <p><strong>DATA:</strong> Two cases of Iresine Syndrome on Hurada Three – right at the time Tarmin and his group was there.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">r.case_id</span><span class="p">,</span> <span class="n">r.planet</span><span class="p">,</span> <span class="n">r.patient</span><span class="p">,</span> <span class="n">r.stardate</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="n">m.arrived_stardate</span> <span class="o">||</span> <span class="s1">'-'</span> <span class="o">||</span> <span class="n">m.departed_stardate</span>
      <span class="k">FROM</span> <span class="n">missions</span> <span class="n">m</span> <span class="k">WHERE</span> <span class="n">m.delegation</span> <span class="o">=</span> <span class="s1">'Ullian'</span>
    <span class="k">AND</span> <span class="n">m.planet</span> <span class="o">=</span> <span class="n">r.planet</span> <span class="k">AND</span> <span class="n">r.stardate</span> <span class="k">BETWEEN</span> <span class="n">m.arrived_stardate</span>
    <span class="k">AND</span> <span class="n">m.departed_stardate</span><span class="p">)</span> <span class="k">AS</span> <span class="n">ullian_visit</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">string_agg</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">l.member</span><span class="p">,</span> <span class="s1">', '</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">l.member</span><span class="p">)</span>
      <span class="k">FROM</span> <span class="n">mission_logs</span> <span class="n">l</span> <span class="k">WHERE</span> <span class="n">l.delegation</span> <span class="o">=</span> <span class="s1">'Ullian'</span>
    <span class="k">AND</span> <span class="n">l.planet</span> <span class="o">=</span> <span class="n">r.planet</span> <span class="k">AND</span> <span class="n">r.stardate</span> <span class="k">BETWEEN</span> <span class="n">l.arrived_stardate</span>
    <span class="k">AND</span> <span class="n">l.departed_stardate</span><span class="p">)</span> <span class="k">AS</span> <span class="n">ullians_present</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">string_agg</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">m.delegation</span><span class="p">,</span> <span class="s1">', '</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">missions</span> <span class="n">m</span>
      <span class="k">WHERE</span> <span class="n">m.delegation</span> <span class="o">&lt;&gt;</span> <span class="s1">'Ullian'</span> <span class="k">AND</span> <span class="n">m.planet</span> <span class="o">=</span> <span class="n">r.planet</span>
    <span class="k">AND</span> <span class="n">r.stardate</span> <span class="k">BETWEEN</span> <span class="n">m.arrived_stardate</span>
    <span class="k">AND</span> <span class="n">m.departed_stardate</span><span class="p">)</span> <span class="k">AS</span> <span class="n">other_delegations_present</span>
<span class="k">FROM</span> <span class="n">planetary_medical_records</span> <span class="n">r</span>
<span class="k">WHERE</span> <span class="n">r.diagnosis</span> <span class="o">=</span> <span class="s1">'Iresine Syndrome'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">r.stardate</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 7 rows.</caption>
<tr><th>case_id</th><th>planet</th><th>patient</th><th>stardate</th><th>ullian_visit</th><th>ullians_present</th><th>other_delegations_present</th></tr>
<tr><td>212105</td><td>Hurada III</td><td>HUR-1310</td><td>41194</td><td>NULL</td><td>NULL</td><td>Vulcan Science Academy</td></tr>
<tr><td>212107</td><td>Varnis VI</td><td>VAR-0802</td><td>42603</td><td>NULL</td><td>NULL</td><td>NULL</td></tr>
<tr><td>212101</td><td>Teloria III</td><td>TEL3-0418</td><td>43304</td><td>43186-43380</td><td>Inad, Jev, Tarmin</td><td>NULL</td></tr>
<tr><td>212102</td><td>Hurada III</td><td>HUR-2207</td><td>43531</td><td>43424-43712</td><td>Inad, Jev, Tarmin</td><td>NULL</td></tr>
<tr><td>212106</td><td>Brevin V</td><td>BRV-0551</td><td>43547</td><td>NULL</td><td>NULL</td><td>Vulcan Science Academy</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> Let’s try the other planets. I think we may have something.</p>

  <p><strong>PICARD:</strong> How’s your search coming?</p>

  <p><strong>DATA:</strong> We have uncovered several cases, sir, but we have not yet completed our search.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">WITH</span> <span class="n">comas</span> <span class="k">AS</span> <span class="p">(</span>
  <span class="k">SELECT</span> <span class="n">planet</span><span class="p">,</span> <span class="n">stardate</span> <span class="k">FROM</span> <span class="n">coma_incidents</span>
  <span class="nb">UNION</span>
  <span class="k">SELECT</span> <span class="n">planet</span><span class="p">,</span> <span class="n">stardate</span>
  <span class="k">FROM</span> <span class="n">planetary_medical_records</span>
  <span class="k">WHERE</span> <span class="n">diagnosis</span> <span class="o">=</span> <span class="s1">'Iresine Syndrome'</span>
<span class="p">)</span>
<span class="k">SELECT</span> <span class="n">m.planet</span><span class="p">,</span> <span class="n">m.arrived_stardate</span><span class="p">,</span> <span class="n">m.departed_stardate</span><span class="p">,</span>
       <span class="n">c.stardate</span> <span class="k">AS</span> <span class="n">coma_stardate</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="n">r.diagnosis</span> <span class="k">FROM</span> <span class="n">planetary_medical_records</span> <span class="n">r</span>
      <span class="k">WHERE</span> <span class="n">r.planet</span> <span class="o">=</span> <span class="n">c.planet</span> <span class="k">AND</span> <span class="n">r.stardate</span> <span class="o">=</span> <span class="n">c.stardate</span>
    <span class="k">AND</span> <span class="n">r.condition</span> <span class="o">=</span> <span class="s1">'coma'</span><span class="p">)</span> <span class="k">AS</span> <span class="n">recorded_diagnosis</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">string_agg</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">l.member</span><span class="p">,</span> <span class="s1">', '</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">l.member</span><span class="p">)</span>
      <span class="k">FROM</span> <span class="n">mission_logs</span> <span class="n">l</span> <span class="k">WHERE</span> <span class="n">l.delegation</span> <span class="o">=</span> <span class="s1">'Ullian'</span>
    <span class="k">AND</span> <span class="n">l.planet</span> <span class="o">=</span> <span class="n">c.planet</span> <span class="k">AND</span> <span class="n">c.stardate</span> <span class="k">BETWEEN</span> <span class="n">l.arrived_stardate</span>
    <span class="k">AND</span> <span class="n">l.departed_stardate</span><span class="p">)</span> <span class="k">AS</span> <span class="n">ullians_present</span>
<span class="k">FROM</span> <span class="n">missions</span> <span class="n">m</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">comas</span> <span class="n">c</span> <span class="k">ON</span> <span class="n">c.planet</span> <span class="o">=</span> <span class="n">m.planet</span>
  <span class="k">AND</span> <span class="n">c.stardate</span> <span class="k">BETWEEN</span> <span class="n">m.arrived_stardate</span> <span class="k">AND</span> <span class="n">m.departed_stardate</span>
<span class="k">WHERE</span> <span class="n">m.delegation</span> <span class="o">=</span> <span class="s1">'Ullian'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">m.arrived_stardate</span><span class="p">,</span> <span class="n">c.stardate</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 14 rows.</caption>
<tr><th>planet</th><th>arrived_stardate</th><th>departed_stardate</th><th>coma_stardate</th><th>recorded_diagnosis</th><th>ullians_present</th></tr>
<tr><td>Jessen I</td><td>42186</td><td>42465</td><td>NULL</td><td>NULL</td><td>NULL</td></tr>
<tr><td>Jessen IV</td><td>42498</td><td>42786</td><td>NULL</td><td>NULL</td><td>NULL</td></tr>
<tr><td>Jessen I</td><td>42810</td><td>42900</td><td>NULL</td><td>NULL</td><td>NULL</td></tr>
<tr><td>Teloria II</td><td>43030</td><td>43172</td><td>NULL</td><td>NULL</td><td>NULL</td></tr>
<tr><td>Teloria III</td><td>43186</td><td>43380</td><td>43304</td><td>Iresine Syndrome</td><td>Inad, Jev, Tarmin</td></tr>
</table>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">WITH</span> <span class="n">comas</span> <span class="k">AS</span> <span class="p">(</span>
  <span class="k">SELECT</span> <span class="n">planet</span><span class="p">,</span> <span class="n">stardate</span> <span class="k">FROM</span> <span class="n">coma_incidents</span>
  <span class="nb">UNION</span>
  <span class="k">SELECT</span> <span class="n">r.planet</span><span class="p">,</span> <span class="n">r.stardate</span>
  <span class="k">FROM</span> <span class="n">planetary_medical_records</span> <span class="n">r</span>
  <span class="k">JOIN</span> <span class="n">missions</span> <span class="n">m</span> <span class="k">ON</span> <span class="n">m.delegation</span><span class="o">=</span><span class="s1">'Ullian'</span> <span class="k">AND</span> <span class="n">m.planet</span> <span class="o">=</span> <span class="n">r.planet</span>
    <span class="k">AND</span> <span class="n">r.stardate</span> <span class="k">BETWEEN</span> <span class="n">m.arrived_stardate</span> <span class="k">AND</span> <span class="n">m.departed_stardate</span>
  <span class="k">WHERE</span> <span class="n">r.diagnosis</span> <span class="o">=</span> <span class="s1">'Iresine Syndrome'</span>
<span class="p">)</span>
<span class="k">SELECT</span> <span class="n">l.member</span><span class="p">,</span>
       <span class="nf">count</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="p">(</span><span class="n">c.planet</span><span class="p">,</span> <span class="n">c.stardate</span><span class="p">))</span> <span class="k">AS</span> <span class="n">comas_present_for</span><span class="p">,</span>
       <span class="p">(</span><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">comas</span><span class="p">)</span> <span class="k">AS</span> <span class="n">total_comas</span>
<span class="k">FROM</span> <span class="n">comas</span> <span class="n">c</span>
<span class="k">JOIN</span> <span class="n">mission_logs</span> <span class="n">l</span> <span class="k">ON</span> <span class="n">l.delegation</span> <span class="o">=</span> <span class="s1">'Ullian'</span> <span class="k">AND</span> <span class="n">l.planet</span> <span class="o">=</span> <span class="n">c.planet</span>
  <span class="k">AND</span> <span class="n">c.stardate</span> <span class="k">BETWEEN</span> <span class="n">l.arrived_stardate</span> <span class="k">AND</span> <span class="n">l.departed_stardate</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">l.member</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">comas_present_for</span> <span class="k">DESC</span><span class="p">,</span> <span class="n">l.member</span>
</code></pre></div></div>

<table class="result">
<tr><th>member</th><th>comas_present_for</th><th>total_comas</th></tr>
<tr><td>Jev</td><td>6</td><td>6</td></tr>
<tr><td>Inad</td><td>5</td><td>6</td></tr>
<tr><td>Tarmin</td><td>4</td><td>6</td></tr>
</table>

<p><em>Not what the script says: The three planets were already given on the previous line; here it adds the two Nel III comas, which the dialogue has not received yet at this point.</em></p>

<p><strong>The alibi, and the one who was always there</strong></p>

<figure class="image"><img src="/images/blog/star-trek/enterprise-computer/violations_alibi.jpg" alt="The follow-up search of the Nel system records, correlated with the Ullians’ mission logs." class="center" width="480" /><figcaption>The follow-up search of the Nel system records, correlated with the Ullians’ mission logs. <em>Star Trek: The Next Generation</em>, “Violations” (1992). © CBS Studios Inc.</figcaption></figure>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>GEORDI:</strong> We just got the transmission from the Nel system. No mention of Iresine Syndrome… but there are two unexplained comas on one planet… none on the other.</p>

  <p><strong>DATA:</strong> And were the Ullians present?</p>

  <p><strong>GEORDI:</strong> Checking their mission logs… That’s funny…</p>

  <p><strong>DATA:</strong> What is it?</p>

  <p><strong>GEORDI:</strong> On stardates 45321 and 45323, when the comas occurred… Tarmin was on his home planet. He wasn’t anywhere near the Nel system.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">m.planet</span><span class="p">,</span> <span class="n">m.arrived_stardate</span><span class="p">,</span> <span class="n">m.departed_stardate</span><span class="p">,</span> <span class="n">c.incident_id</span><span class="p">,</span>
       <span class="n">c.stardate</span> <span class="k">AS</span> <span class="n">coma_stardate</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">string_agg</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">l.member</span><span class="p">,</span> <span class="s1">', '</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">l.member</span><span class="p">)</span>
      <span class="k">FROM</span> <span class="n">mission_logs</span> <span class="n">l</span> <span class="k">WHERE</span> <span class="n">l.delegation</span> <span class="o">=</span> <span class="s1">'Ullian'</span>
    <span class="k">AND</span> <span class="n">l.planet</span> <span class="o">=</span> <span class="n">c.planet</span> <span class="k">AND</span> <span class="n">c.stardate</span> <span class="k">BETWEEN</span> <span class="n">l.arrived_stardate</span>
    <span class="k">AND</span> <span class="n">l.departed_stardate</span><span class="p">)</span> <span class="k">AS</span> <span class="n">ullians_present</span><span class="p">,</span>
  <span class="p">(</span><span class="k">SELECT</span> <span class="nf">string_agg</span><span class="p">(</span><span class="n">l.member</span> <span class="o">||</span> <span class="s1">' on '</span> <span class="o">||</span> <span class="n">l.planet</span><span class="p">,</span> <span class="s1">', '</span><span class="p">)</span>
      <span class="k">FROM</span> <span class="n">mission_logs</span> <span class="n">l</span> <span class="k">WHERE</span> <span class="n">l.delegation</span> <span class="o">=</span> <span class="s1">'Ullian'</span>
    <span class="k">AND</span> <span class="n">l.planet</span> <span class="o">&lt;&gt;</span> <span class="n">m.planet</span> <span class="k">AND</span> <span class="n">c.stardate</span> <span class="k">BETWEEN</span> <span class="n">l.arrived_stardate</span>
    <span class="k">AND</span> <span class="n">l.departed_stardate</span><span class="p">)</span> <span class="k">AS</span> <span class="n">ullians_elsewhere</span>
<span class="k">FROM</span> <span class="n">missions</span> <span class="n">m</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">coma_incidents</span> <span class="n">c</span> <span class="k">ON</span> <span class="n">c.planet</span> <span class="o">=</span> <span class="n">m.planet</span>
  <span class="k">AND</span> <span class="n">c.stardate</span> <span class="k">BETWEEN</span> <span class="n">m.arrived_stardate</span> <span class="k">AND</span> <span class="n">m.departed_stardate</span>
<span class="k">WHERE</span> <span class="n">m.delegation</span> <span class="o">=</span> <span class="s1">'Ullian'</span> <span class="k">AND</span> <span class="n">m.planet</span> <span class="k">LIKE</span> <span class="s1">'Nel %'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">m.arrived_stardate</span><span class="p">,</span> <span class="n">c.stardate</span>
</code></pre></div></div>

<table class="result">
<tr><th>planet</th><th>arrived_stardate</th><th>departed_stardate</th><th>incident_id</th><th>coma_stardate</th><th>ullians_present</th><th>ullians_elsewhere</th></tr>
<tr><td>Nel II</td><td>45123</td><td>45260</td><td>NULL</td><td>NULL</td><td>NULL</td><td>NULL</td></tr>
<tr><td>Nel III</td><td>45273</td><td>45383</td><td>5</td><td>45321</td><td>Inad, Jev</td><td>Tarmin on Ullian homeworld</td></tr>
<tr><td>Nel III</td><td>45273</td><td>45383</td><td>6</td><td>45323</td><td>Inad, Jev</td><td>Tarmin on Ullian homeworld</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>DATA:</strong> We discovered two instances of unexplained comas on Nel Three while the Ullians were there… but Tarmin was not part of the group. A closer examination revealed that only one Ullian was present at all incidents of coma – Jev.</p>
</blockquote>

<p><em>Nobody speaks this request in the script. Claude was asked: “Were any of the Ullians present at all incidents of coma?”</em></p>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">l.member</span><span class="p">,</span> <span class="nf">count</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">c.incident_id</span><span class="p">)</span> <span class="k">AS</span> <span class="n">incidents_present</span><span class="p">,</span>
       <span class="p">(</span><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">coma_incidents</span><span class="p">)</span> <span class="k">AS</span> <span class="n">total_incidents</span>
<span class="k">FROM</span> <span class="n">coma_incidents</span> <span class="n">c</span>
<span class="k">JOIN</span> <span class="n">mission_logs</span> <span class="n">l</span> <span class="k">ON</span> <span class="n">l.delegation</span> <span class="o">=</span> <span class="s1">'Ullian'</span> <span class="k">AND</span> <span class="n">l.planet</span> <span class="o">=</span> <span class="n">c.planet</span>
  <span class="k">AND</span> <span class="n">c.stardate</span> <span class="k">BETWEEN</span> <span class="n">l.arrived_stardate</span> <span class="k">AND</span> <span class="n">l.departed_stardate</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">l.member</span>
<span class="k">HAVING</span> <span class="nf">count</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">c.incident_id</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span>
    <span class="k">FROM</span> <span class="n">coma_incidents</span><span class="p">)</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">l.member</span>
</code></pre></div></div>

<table class="result">
<tr><th>member</th><th>incidents_present</th><th>total_incidents</th></tr>
<tr><td>Jev</td><td>6</td><td>6</td></tr>
</table>

<h3 id="realm-of-fear">Realm of Fear</h3>

<p><a href="https://www.st-minutiae.com/resources/scripts/228.txt">Script</a>. Season 6. Barclay, who is afraid of the transporter, looks up what it might be doing to him.</p>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>BARCLAY:</strong> Computer… access Starfleet Medical Data Base. Tell me about… describe the disorder known as… Transporter Psychosis.</p>

  <p><strong>COMPUTER:</strong> Transporter Psychosis was diagnosed in the year twenty-two-oh-nine by researchers on Delinia Two –</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">disorder</span><span class="p">,</span> <span class="n">summary</span><span class="p">,</span> <span class="n">year_diagnosed</span><span class="p">,</span> <span class="n">diagnosed_by</span><span class="p">,</span> <span class="n">diagnosed_at</span><span class="p">,</span>
       <span class="n">cause</span>
<span class="k">FROM</span> <span class="n">medical_database</span> <span class="k">WHERE</span> <span class="n">disorder</span> <span class="k">ILIKE</span> <span class="s1">'Transporter Psychosis'</span>
</code></pre></div></div>

<table class="result">
<tr><th>disorder</th><th>summary</th><th>year_diagnosed</th><th>diagnosed_by</th><th>diagnosed_at</th><th>cause</th></tr>
<tr><td>Transporter Psychosis</td><td>Transporter Psychosis was diagnosed in the year twenty-two-oh-nine …</td><td>2209</td><td>researchers</td><td>Delinia II</td><td>It is caused by a breakdown of neuro-chemical molecules during tran…</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>BARCLAY:</strong> No, no… stop. All I need is the… what causes it?</p>

  <p><strong>COMPUTER:</strong> It is caused by a breakdown of neuro-chemical molecules during transport, affecting the body’s motor functions, autonomic systems, and the brain’s higher reasoning centers.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">cause</span>
<span class="k">FROM</span> <span class="n">medical_database</span>
<span class="k">WHERE</span> <span class="n">disorder</span> <span class="k">ILIKE</span> <span class="s1">'Transporter Psychosis'</span>
</code></pre></div></div>

<table class="result">
<tr><th>cause</th></tr>
<tr><td>It is caused by a breakdown of neuro-chemical molecules during tran…</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>BARCLAY:</strong> What are the symptoms?</p>

  <p><strong>COMPUTER:</strong> Victims suffer from paranoid delusions… multi-infarct dementia… hallucinations…</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">symptom_id</span><span class="p">,</span> <span class="n">symptom</span><span class="p">,</span> <span class="n">category</span><span class="p">,</span> <span class="n">detail</span><span class="p">,</span> <span class="n">is_peripheral</span>
<span class="k">FROM</span> <span class="n">disorder_symptoms</span> <span class="k">WHERE</span> <span class="n">disorder</span> <span class="k">ILIKE</span> <span class="s1">'Transporter Psychosis'</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">symptom_id</span>
</code></pre></div></div>

<table class="result">
<caption>First 5 of 8 rows.</caption>
<tr><th>symptom_id</th><th>symptom</th><th>category</th><th>detail</th><th>is_peripheral</th></tr>
<tr><td>22801</td><td>paranoid delusions</td><td>delusion</td><td>NULL</td><td>false</td></tr>
<tr><td>22802</td><td>multi-infarct dementia</td><td>dementia</td><td>NULL</td><td>false</td></tr>
<tr><td>22803</td><td>hallucinations</td><td>hallucination</td><td>Victims experience somatic, tactile and visual hallucinations, acco…</td><td>false</td></tr>
<tr><td>22804</td><td>sleeplessness</td><td>sleep</td><td>NULL</td><td>true</td></tr>
<tr><td>22805</td><td>accelerated heart-rate</td><td>cardiac</td><td>NULL</td><td>true</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>BARCLAY:</strong> Hallucinations? What kind of hallucinations?</p>

  <p><strong>COMPUTER:</strong> Victims experience somatic, tactile and visual hallucinations, accompanied by psychogenic hysteria.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">symptom</span><span class="p">,</span> <span class="n">detail</span> <span class="k">FROM</span> <span class="n">disorder_symptoms</span>
<span class="k">WHERE</span> <span class="n">disorder</span> <span class="k">ILIKE</span> <span class="s1">'Transporter Psychosis'</span>
  <span class="k">AND</span> <span class="n">category</span> <span class="o">=</span> <span class="s1">'hallucination'</span>
</code></pre></div></div>

<table class="result">
<tr><th>symptom</th><th>detail</th></tr>
<tr><td>hallucinations</td><td>Victims experience somatic, tactile and visual hallucinations, acco…</td></tr>
</table>

<p><strong>In the script</strong></p>

<blockquote>
  <p>ShowQuote</p>

  <p><strong>BARCLAY:</strong> Computer… what is the treatment for Transporter Psychosis?</p>

  <p><strong>COMPUTER:</strong> There is no known treatment.</p>
</blockquote>

<p><strong>What the computer ran</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">m.disorder</span><span class="p">,</span> <span class="nf">count</span><span class="p">(</span><span class="n">t.treatment_id</span><span class="p">)</span> <span class="k">AS</span> <span class="n">treatments_on_file</span><span class="p">,</span>
       <span class="p">(</span><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span>
    <span class="k">FROM</span> <span class="n">disorder_treatments</span><span class="p">)</span> <span class="k">AS</span> <span class="n">treatments_in_database</span>
<span class="k">FROM</span> <span class="n">medical_database</span> <span class="n">m</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">disorder_treatments</span> <span class="n">t</span> <span class="k">ON</span> <span class="n">t.disorder</span> <span class="k">ILIKE</span> <span class="s1">'%'</span> <span class="o">||</span> <span class="n">m.disorder</span> <span class="o">||</span> <span class="s1">'%'</span> <span class="k">OR</span> <span class="n">t.disorder</span> <span class="k">ILIKE</span> <span class="s1">'%transporter%'</span> <span class="k">OR</span> <span class="n">t.disorder</span> <span class="k">ILIKE</span> <span class="s1">'%psychosis%'</span>
<span class="k">WHERE</span> <span class="n">m.disorder</span> <span class="k">ILIKE</span> <span class="s1">'Transporter Psychosis'</span> <span class="k">GROUP</span> <span class="k">BY</span> <span class="n">m.disorder</span>
</code></pre></div></div>

<table class="result">
<tr><th>disorder</th><th>treatments_on_file</th><th>treatments_in_database</th></tr>
<tr><td>Transporter Psychosis</td><td>0</td><td>6</td></tr>
</table>

<p><em>Stills from</em> Star Trek: The Next Generation <em>are © CBS Studios Inc. STAR TREK and related marks are trademarks of CBS Studios Inc. They are reproduced here in reduced size for the purpose of commentary on the scenes discussed. This post is not affiliated with or endorsed by CBS Studios or Paramount.</em></p>]]></content>
      

      
        <author>
          <name>Hannes Mühleisen</name>
        </author>
      

      
        
      

      
        <category term="using DuckDB" />
      

      
      
        <summary type="html"><![CDATA[For seven seasons, the crew of the Enterprise talked to the ship’s computer and solved hard data problems. We gave Claude a DuckDB database and the crew’s actual lines to see whether we have the Enterprise computer now.]]></summary>
      

      
      
        
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://duckdb.org/images/blog/thumbs/star-trek.png" />
        <media:content medium="image" url="https://duckdb.org/images/blog/thumbs/star-trek.png" xmlns:media="http://search.yahoo.com/mrss/" />
      
    </entry>
  
    <entry>
      

      <title type="html">How SproutMe Cut Integration Test Time by 92.9% with DuckDB</title>
      <link href="https://duckdb.org/2026/11/24/sproutme-faster-pipeline-testing.html" rel="alternate" type="text/html" title="How SproutMe Cut Integration Test Time by 92.9% with DuckDB" />
      <published>2026-11-24T00:00:00+00:00</published>
      <updated>2026-11-24T00:00:00+00:00</updated>
      <id>https://duckdb.org/2026/11/24/sproutme-faster-pipeline-testing</id>
      
      
        <content type="html" xml:base="https://duckdb.org/2026/11/24/sproutme-faster-pipeline-testing.html"><![CDATA[<h2 id="why-iteration-speed-matters-at-sproutme">Why Iteration Speed Matters at SproutMe</h2>

<p><a href="https://sproutme.ai/">SproutMe</a> is an AI workspace that gives marketers and agencies the playbooks large advertisers run in-house: competitive analysis, account audits, cross-channel optimization and more. AI agents do most of the work, leaving marketers free to focus on long-term strategy. SproutMe was founded by <a href="https://pulkitkhurana.com/">Pulkit Khurana</a>, who spent 13 years at Google, most recently as Engineering Director for Google Ads.</p>

<p>Archit built SproutMe’s data platform from scratch. For a company moving this fast, development speed directly affects the business. <strong>“Because we are a startup, we have to work very fast,”</strong> he says. In practice, that means shipping two to three pull requests a day without breaking anything for the businesses already using the product. <strong>“We don’t want the businesses to face problems when we push it,”</strong> Archit explains, so every change runs end to end, both locally and in CI, before it reaches the main branch.</p>

<p>Local and CI runs were slow. The pipeline handles a lot of data. When a new customer joins, SproutMe pulls about 365 days of history across its ad and analytics sources, which means millions of rows to load and transform. On BigQuery, testing a change at that scale took long enough to disrupt the team’s daily rhythm.</p>

<h2 id="where-duckdb-fits">Where DuckDB Fits</h2>

<p>Archit first heard about DuckDB in LinkedIn posts about its speed. He decided to try it on a few small runs, and it soon became part of the daily workflow. SproutMe now uses DuckDB for local end-to-end testing and CI integration tests.</p>

<p>The pipeline looks like this:</p>

<ol>
  <li><a href="https://dagster.io/">Dagster</a> orchestrates extraction from Google Ads, Meta Ads, and GA4.</li>
  <li>The extracted data lands in DuckDB, which acts as the analytical warehouse on the engineer’s local machine.</li>
  <li><a href="https://www.getdbt.com/">dbt</a> runs the transformations on DuckDB, following a medallion architecture: bronze for raw data, silver for cleaned and standardized data, and gold for the user-facing models.</li>
  <li>The same logic runs locally and in CI before any change is deployed.</li>
</ol>

<p>When the local Dagster dev server starts, it points the pipeline at a DuckDB file through environment variables, and dbt builds into it with the duckdb target. Production stays on BigQuery.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>

<span class="k">def</span> <span class="nf">use_local_duckdb</span><span class="p">(</span><span class="n">warehouse</span><span class="p">:</span> <span class="n">Path</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span><span class="p">:</span>
    <span class="s">"""Point the local pipeline at a DuckDB file instead of BigQuery."""</span>
    <span class="n">warehouse</span><span class="p">.</span><span class="n">parent</span><span class="p">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">os</span><span class="p">.</span><span class="n">environ</span><span class="p">[</span><span class="s">"WAREHOUSE"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"duckdb"</span>
    <span class="n">os</span><span class="p">.</span><span class="n">environ</span><span class="p">[</span><span class="s">"DBT_DUCKDB_PATH"</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">warehouse</span><span class="p">)</span>
    <span class="c1"># BigQuery compares timestamps in UTC; DuckDB uses the machine’s zone unless told otherwise.
</span>    <span class="n">os</span><span class="p">.</span><span class="n">environ</span><span class="p">[</span><span class="s">"TZ"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"UTC"</span>
</code></pre></div></div>

<p>The transformation stage is where DuckDB saves the most time. <strong>“This is where we are saving a lot of time, the transformation part,”</strong> Archit says. Extraction benefits as well, because Dagster writes directly into DuckDB. The scope matters, though: <strong>“It is part of the local development pipeline.”</strong> Production still runs on BigQuery.</p>

<h2 id="the-numbers">The Numbers</h2>

<p>SproutMe chose BigQuery early because the team was already familiar with Google’s infrastructure. A full end-to-end run there can take one to two hours. That works for production, but it is too slow for a team pushing several changes a day and waiting on feedback from local and CI runs each time.</p>

<p>Running the same pipeline on DuckDB shortens the wait between changes. In SproutMe’s measurements, the same dbt project, command, and real data ran on both engines. The integration test step, which runs on every merge, fell from a median of 10.65 minutes (639.0 seconds) to <strong>0.76 minutes (45.6 seconds)</strong>. That is a 92.9 percent reduction across 88 CI/CD runs. The dbt runs also got faster. On local test accounts, a full backfill dropped from 180.2 seconds to 104.6 seconds, and a daily incremental build dropped from 300.3 seconds to 120.7 seconds. DuckDB times are medians of five runs. The table below lists all timings in seconds.</p>

<div class="center_aligned_header_table"></div>

<table>
  <thead>
    <tr>
      <th>What we measured</th>
      <th style="text-align: right">BigQuery</th>
      <th style="text-align: right">DuckDB</th>
      <th style="text-align: right">Time saved</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Integration test step, per merge</td>
      <td style="text-align: right">639.0 s</td>
      <td style="text-align: right">45.6 s</td>
      <td style="text-align: right">92.9%</td>
    </tr>
    <tr>
      <td>Full dbt backfill</td>
      <td style="text-align: right">180.2 s</td>
      <td style="text-align: right">104.6 s</td>
      <td style="text-align: right">42.0%</td>
    </tr>
    <tr>
      <td>Daily incremental dbt build</td>
      <td style="text-align: right">300.3 s</td>
      <td style="text-align: right">120.7 s</td>
      <td style="text-align: right">59.8%</td>
    </tr>
    <tr>
      <td>Backfill and daily build together</td>
      <td style="text-align: right">480.5 s</td>
      <td style="text-align: right">225.3 s</td>
      <td style="text-align: right">53.1%</td>
    </tr>
  </tbody>
</table>

<p>SproutMe’s platform uses AI agents to generate recommendations like those shown in the dashboard below, which displays performance metrics, trends, and recommended actions across multiple channels.</p>

<p><img src="/images/blog/sproutme_dashboard.png" alt="SproutMe dashboard showing campaign performance and recommendations" /></p>

<p>SproutMe’s AI companion can also run analysis tasks like competitor research, producing structured reports with executive summaries and actionable insights, as shown below.</p>

<p><img src="/images/blog/sproutme_companion.png" alt="SproutMe AI companion generating a competitor analysis report" /></p>

<p>In CI, dbt build runs with the duckdb target over the whole project, seeded from committed fixtures. The integration tests then compare selected models’ output with committed golden files, so a regression fails the build before it reaches main.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>

<span class="k">def</span> <span class="nf">build_test_warehouse</span><span class="p">(</span><span class="n">db_path</span><span class="p">:</span> <span class="n">Path</span><span class="p">,</span> <span class="n">project_dir</span><span class="p">:</span> <span class="n">Path</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span><span class="p">:</span>
    <span class="s">"""dbt build of the whole project on DuckDB, after the committed fixtures are loaded."""</span>
    <span class="n">env</span> <span class="o">=</span> <span class="p">{</span><span class="o">**</span><span class="n">os</span><span class="p">.</span><span class="n">environ</span><span class="p">,</span> <span class="s">"DBT_DUCKDB_PATH"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">db_path</span><span class="p">)}</span>
    <span class="n">subprocess</span><span class="p">.</span><span class="n">run</span><span class="p">(</span>
        <span class="p">[</span><span class="s">"dbt"</span><span class="p">,</span> <span class="s">"build"</span><span class="p">,</span> <span class="s">"--target"</span><span class="p">,</span> <span class="s">"duckdb"</span><span class="p">,</span>
         <span class="s">"--project-dir"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">project_dir</span><span class="p">),</span> <span class="s">"--profiles-dir"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">project_dir</span><span class="p">)],</span>
        <span class="n">env</span><span class="o">=</span><span class="n">env</span><span class="p">,</span>
        <span class="n">check</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
    <span class="p">)</span>
</code></pre></div></div>

<p>These results apply to SproutMe’s development and testing workflow. They do not show that one engine is faster in general.</p>

<p>For Archit, the main gain is faster debugging. Instead of spending hours reproducing an issue, he can find a bug in minutes. <strong>“Development speed is super fast,”</strong> he says, pointing to three advantages: rapid iteration locally, how easily DuckDB runs on local machines with AI coding assistants like Claude (which can inspect errors and help debug directly), and compatibility—the same setup works in both local development and CI without changes.</p>

<h2 id="what-comes-next">What Comes Next</h2>

<p>SproutMe has used DuckDB for only a month or two, but the results have made the team curious about going further. Archit is open to using DuckDB in production if more testing and benchmarking support it.</p>

<p>He also points out that moving a production workload that serves live customers needs its own evaluation. For now, the change is limited to development, and the production warehouse stays the same.</p>

<h2 id="the-takeaway">The Takeaway</h2>

<p>SproutMe shows that DuckDB can fit into an existing Cloud data architecture without replacing anything in production. The integration tests now finish in under a minute, which keeps pace with the team. Feedback arrives sooner, which lowers the risk of shipping a regression, and BigQuery keeps serving the live product.</p>

<p>We would like to thank Archit for the conversation. If you use DuckDB and want to share your story, email <a href="mailto:geertjan@ducklabs.com">geertjan@ducklabs.com</a>.</p>]]></content>
      

      
        <author>
          <name>Archit Dukhande</name>
        </author>
      
        <author>
          <name>Geertjan Wielenga</name>
        </author>
      
        <author>
          <name>Tim Cox</name>
        </author>
      

      
        
      

      
        <category term="using-duckdb" />
      

      
      
        <summary type="html"><![CDATA[At [SproutMe](https://sproutme.ai/), a fast-moving, early-stage AI marketing startup, data engineer [Archit Dukhande](https://www.linkedin.com/in/archit-dukhande/) added DuckDB to their local development and CI workflow for a data-heavy AI product. Running the integration tests on DuckDB cut the step per merge by 92.9 percent, from 10.65 minutes to 0.76 minutes, so the team can ship several changes a day without putting users at risk.]]></summary>
      

      
      
        
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://duckdb.org/images/blog/thumbs/sproutme.png" />
        <media:content medium="image" url="https://duckdb.org/images/blog/thumbs/sproutme.png" xmlns:media="http://search.yahoo.com/mrss/" />
      
    </entry>
  
    <entry>
      

      <title type="html">Announcing DuckDB 2.0.1 LTS</title>
      <link href="https://duckdb.org/2026/11/20/announcing-duckdb-201.html" rel="alternate" type="text/html" title="Announcing DuckDB 2.0.1 LTS" />
      <published>2026-11-20T00:00:00+00:00</published>
      <updated>2026-11-20T00:00:00+00:00</updated>
      <id>https://duckdb.org/2026/11/20/announcing-duckdb-201</id>
      
      
        <content type="html" xml:base="https://duckdb.org/2026/11/20/announcing-duckdb-201.html"><![CDATA[<p>Today we're releasing DuckDB 2.0.1, the first patch release in the <a href="/2026/10/21/announcing-duckdb-200.html">2.0 LTS (Cyanoptera) line</a>. This planned release arrives one month after 2.0.0 and contains bugfixes, performance improvements, and security patches. In addition, it provides a more convenient way of registering custom extension repositories and it ships Sirius, a new core extension for running DuckDB queries natively on NVIDIA GPUs.</p>

<p>You can obtain a copy from the <a href="/docs/2.0/installation.html">installation page</a>. For a detailed overview of the changes, see the <a href="https://github.com/duckdb/duckdb/releases/tag/v2.0.1">release notes on GitHub</a>. Read on for some highlights.</p>

<h2 id="changes-that-may-require-action">Changes That May Require Action</h2>

<p>A few fixes in this release change existing behavior. In each case, the previous behavior was incorrect or a security risk, so we chose to fix it in 2.0.1 rather than wait for the next major release. If you rely on any of the behaviors below, review them before upgrading.</p>

<h3 id="stricter-secret-scope-matching">Stricter <code class="language-plaintext highlighter-rouge">SECRET</code> Scope Matching</h3>

<p>A <code class="language-plaintext highlighter-rouge">SECRET</code> scoped to a host or bucket could also match other hosts or buckets with the same prefix, so it could be sent somewhere it wasn't meant for (<a href="https://github.com/duckdb/duckdb/pull/28684"><code class="language-plaintext highlighter-rouge">#28684</code></a>). A URL now matches such a scope only if it is identical to the scope or continues with a <code class="language-plaintext highlighter-rouge">/</code>. For example, the scope <code class="language-plaintext highlighter-rouge">s3://bucket-</code> no longer matches <code class="language-plaintext highlighter-rouge">s3://bucket-1/</code>.</p>

<p><strong>Action:</strong> check your host- and bucket-scoped <code class="language-plaintext highlighter-rouge">SECRET</code>s and make sure each scope uses the full host or bucket name. If a URL has an explicit port, the scope must include it too.</p>

<h3 id="update--from-and-merge-again-apply-every-match"><code class="language-plaintext highlighter-rouge">UPDATE ... FROM</code> and <code class="language-plaintext highlighter-rouge">MERGE</code> Again Apply Every Match</h3>

<p>In DuckDB 2.0.0, if several source rows matched the same target row, <code class="language-plaintext highlighter-rouge">MERGE</code> raised an error and <code class="language-plaintext highlighter-rouge">UPDATE ... FROM</code> updated the target row once, using one of the matches. Enforcing this behavior serialized large updates, causing a significant performance regression.</p>

<p>DuckDB 2.0.1 restores the 1.x behavior for both statements (<a href="https://github.com/duckdb/duckdb/pull/28701"><code class="language-plaintext highlighter-rouge">#28701</code></a>): the target row is updated once per match, so the final value can be non-deterministic, and the row is counted and returned (with <code class="language-plaintext highlighter-rouge">RETURNING</code>) once per match.</p>

<p><strong>Action:</strong> review your <code class="language-plaintext highlighter-rouge">UPDATE ... FROM</code> and <code class="language-plaintext highlighter-rouge">MERGE</code> statements. To keep updates deterministic, make sure each target row is matched by at most one source row, or that all matching source rows have identical values for the updated columns.</p>

<p>We expect a fix that keeps both correctness and performance in DuckDB 2.1.</p>

<h2 id="improvement-registering-extension-repositories-by-host">Improvement: Registering Extension Repositories by Host</h2>

<p>DuckDB 2.0.0 introduced <a href="/docs/2.0/extensions/installing_extensions.html#extension-repositories">custom extension repositories</a>, which host extensions signed with the publisher's own keys.
In DuckDB 2.0.1, you can register such a repository by naming the publisher's host (<a href="https://github.com/duckdb/duckdb/pull/28719"><code class="language-plaintext highlighter-rouge">#28719</code></a>).
For example, you can register <code class="language-plaintext highlighter-rouge">duckdb.org</code> as a repository:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">CREATE</span> <span class="k">EXTENSION</span> <span class="k">REPOSITORY</span> <span class="n">duckdb.org</span><span class="p">;</span>
</code></pre></div></div>

<p>Then, core extensions are reachable through it:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">INSTALL AND LOAD</span> <span class="n">spatial</span> <span class="k">FROM</span> <span class="n">duckdb.org</span><span class="p">;</span>
</code></pre></div></div>

<p>Under the hood, the host acts as an extra redirect.
DuckDB first reads <code class="language-plaintext highlighter-rouge">https://duckdb.org/.well-known/duckdb-extension-repo.json</code> over verified HTTPS.
This file contains no keys or extensions: it only states where the host's repository lives, in this case, <code class="language-plaintext highlighter-rouge">https://extensions.duckdb.org</code>.
DuckDB then follows this pointer, reads the repository's own <code class="language-plaintext highlighter-rouge">.well-known/duckdb-extension-repo.json</code> file, and pins the signing keys listed there.
Only the owner of a host can publish files under its <code class="language-plaintext highlighter-rouge">.well-known</code> path, so serving this file is proof of control over the host, and no central registry is involved.
The redirect also decouples the repository's name from its location: the name can be your organization's domain, while the extensions are served from a CDN, an S3 bucket, or GitHub Pages.
The <code class="language-plaintext highlighter-rouge">CREATE EXTENSION REPOSITORY</code> statement returns the SHA-256 fingerprint of each pinned key, so you can compare them against values published through another channel.</p>

<p>The power of this feature lies in the fact that your organization can do the same: publish a <code class="language-plaintext highlighter-rouge">.well-known/duckdb-extension-repo.json</code> file on your own domain, and your users can install your extensions with the same succinct syntax:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">INSTALL AND LOAD</span> <span class="ge">extension</span> <span class="k">FROM</span> <span class="ge">your_domain</span><span class="p">;</span>
</code></pre></div></div>

<p>To get started, see the new <a href="/docs/2.0/extensions/publishing_extension_repositories.html">“Publishing an Extension Repository” page</a>.</p>

<p>Unlike adding a repository by its prefix, adding one by its host does not require an opt-in.
To support this, the <code class="language-plaintext highlighter-rouge">allow_extension_repositories</code> setting has new values: <code class="language-plaintext highlighter-rouge">hosts</code> (the new default) allows adding repositories by host, <code class="language-plaintext highlighter-rouge">allowed</code> also allows adding them by prefix, <code class="language-plaintext highlighter-rouge">hosts_only</code> only adds and trusts repositories resolved from their host, and <code class="language-plaintext highlighter-rouge">forbidden</code> disables custom repositories.
The previous default value, <code class="language-plaintext highlighter-rouge">undecided</code>, is no longer accepted.
If only extensions signed by the DuckDB team should be loaded in your environment, set <code class="language-plaintext highlighter-rouge">allow_extension_repositories</code> to <code class="language-plaintext highlighter-rouge">forbidden</code>.
For details, see the <a href="/docs/2.0/operations_manual/securing_duckdb/securing_extensions.html#custom-extension-repositories">“Securing Extensions” page</a>.</p>

<h2 id="new-core-extension-sirius">New Core Extension: Sirius</h2>

<p>DuckDB 2.0.1 adds <a href="/docs/2.0/core_extensions/sirius.html">Sirius</a>, a GPU-native SQL engine that runs DuckDB queries on NVIDIA GPUs, as a core extension (<a href="https://github.com/duckdb/duckdb/pull/28022"><code class="language-plaintext highlighter-rouge">#28022</code></a>).
Sirius is available on Linux (x86-64 and arm64) and requires an NVIDIA GPU with a CUDA 12 or 13 driver.</p>

<p>To use Sirius, first install and load the extension, and check its status as follows:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">INSTALL AND LOAD</span> <span class="n">httpfs</span><span class="p">;</span>
<span class="k">SET</span> <span class="py">http_timeout</span> <span class="o">=</span> <span class="mi">900</span><span class="p">;</span>
<span class="k">INSTALL AND LOAD</span> <span class="n">sirius</span><span class="p">;</span>
<span class="k">FROM</span> <span class="nf">sirius_status</span><span class="p">();</span>
</code></pre></div></div>

<p>When you load Sirius for the first time, it detects your CUDA version and downloads the matching backend, which is about 1 GB.
If a query uses features that Sirius does not support yet, DuckDB falls back to its CPU engine to run it.</p>

<h2 id="important-fixes">Important Fixes</h2>

<h3 id="silent-data-loss-on-affected-linux-kernels">Silent Data Loss on Affected Linux Kernels</h3>

<p>Some Linux kernel versions have a bug (<a href="https://app.opencve.io/cve/CVE-2026-97945">CVE-2026-97945</a>) that can cause memory freed lazily with <code class="language-plaintext highlighter-rouge">MADV_FREE</code> to be silently zeroed after it has been reused.
DuckDB 2.0.1 avoids this issue: its bundled allocator no longer frees memory this way (<a href="https://github.com/duckdb/duckdb/pull/28267"><code class="language-plaintext highlighter-rouge">#28267</code></a>).
The patch works by setting the bundled jemalloc's <code class="language-plaintext highlighter-rouge">muzzy_decay_ms</code> to <code class="language-plaintext highlighter-rouge">0</code>. If you cannot upgrade right away, you should set the <code class="language-plaintext highlighter-rouge">DUCKDB_JE_MALLOC_CONF</code> environment variable to <code class="language-plaintext highlighter-rouge">muzzy_decay_ms:0</code>, which achieves the same effect.</p>

<h3 id="reading-databases-written-by-duckdb-1x">Reading Databases Written by DuckDB 1.x</h3>

<p>DuckDB 2.0.0 could miss rows with <code class="language-plaintext highlighter-rouge">NULL</code> values when filtering tables in database files written by DuckDB 1.x (<a href="https://github.com/duckdb/duckdb/pull/28355"><code class="language-plaintext highlighter-rouge">#28355</code></a>).
DuckDB 2.0.1 fixes this, along with several issues affecting views, macros, and other objects stored by 1.x versions.</p>

<h3 id="security-fixes">Security Fixes</h3>

<p>We fixed a remote path traversal issue (<a href="https://github.com/duckdb/duckdb/pull/28684"><code class="language-plaintext highlighter-rouge">#28684</code></a>) that occurred when DuckDB was configured with <code class="language-plaintext highlighter-rouge">enable_external_access=false</code>.</p>

<p>Additionally, this release pulls in a fix (<a href="https://github.com/duckdb/duckdb/pull/27791"><code class="language-plaintext highlighter-rouge">#27791</code></a>) for the Brotli decoder (<a href="https://app.opencve.io/cve/CVE-2026-111497">CVE-2026-111497</a>).</p>

<h2 id="other-fixes">Other Fixes</h2>

<p>Here are some other important fixes from the DuckDB 2.0.1 release, organized by category:</p>

<h3 id="correctness">Correctness</h3>

<ul>
  <li><a href="https://github.com/duckdb/duckdb/pull/27514"><code class="language-plaintext highlighter-rouge">#27514</code></a> – Fix <code class="language-plaintext highlighter-rouge">IS NULL</code> pruning of Parquet pages with constant string statistics</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/27923"><code class="language-plaintext highlighter-rouge">#27923</code></a> – Fix <code class="language-plaintext highlighter-rouge">hour</code>, <code class="language-plaintext highlighter-rouge">minute</code>, and <code class="language-plaintext highlighter-rouge">second</code> rounding <code class="language-plaintext highlighter-rouge">TIMESTAMP_NS</code> values up into the next second</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/27779"><code class="language-plaintext highlighter-rouge">#27779</code></a> – Fix <code class="language-plaintext highlighter-rouge">LIMIT</code> being dropped above a join with an aggregate over an empty table</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/28698"><code class="language-plaintext highlighter-rouge">#28698</code></a> – Fix wrong results when a lateral join reads from a CTE</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/28210"><code class="language-plaintext highlighter-rouge">#28210</code></a> – Fix random functions returning the same values in processes cloned with <code class="language-plaintext highlighter-rouge">fork()</code></li>
</ul>

<h3 id="storage-and-transactions">Storage and Transactions</h3>

<ul>
  <li><a href="https://github.com/duckdb/duckdb/pull/27764"><code class="language-plaintext highlighter-rouge">#27764</code></a> – Keep the rows of bulk inserts invisible to other transactions until commit</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/26814"><code class="language-plaintext highlighter-rouge">#26814</code></a> – Fix lost index entries when an automatic checkpoint runs after WAL replay</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/28190"><code class="language-plaintext highlighter-rouge">#28190</code></a> – Fix rows getting lost after a restart that follows a reverted commit</li>
</ul>

<h3 id="crashes-and-internal-errors">Crashes and Internal Errors</h3>

<ul>
  <li><a href="https://github.com/duckdb/duckdb/pull/28293"><code class="language-plaintext highlighter-rouge">#28293</code></a> – Fix crash in <code class="language-plaintext highlighter-rouge">list_select</code> and <code class="language-plaintext highlighter-rouge">list_where</code> on empty lists</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/27596"><code class="language-plaintext highlighter-rouge">#27596</code></a> – Fix window operators hanging when they hit the memory limit</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/27936"><code class="language-plaintext highlighter-rouge">#27936</code></a> – Fix deadlocks in materialized CTEs</li>
</ul>

<h3 id="performance">Performance</h3>

<ul>
  <li><a href="https://github.com/duckdb/duckdb/pull/28646"><code class="language-plaintext highlighter-rouge">#28646</code></a> – Fix aggregates such as <code class="language-plaintext highlighter-rouge">quantile_cont</code> and <code class="language-plaintext highlighter-rouge">arg_max</code> running out of memory on large <code class="language-plaintext highlighter-rouge">GROUP BY</code> queries</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/27760"><code class="language-plaintext highlighter-rouge">#27760</code></a> – Push down filters to <code class="language-plaintext highlighter-rouge">VIEW</code>s used in subqueries, which can make queries orders of magnitude faster</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/27326"><code class="language-plaintext highlighter-rouge">#27326</code></a> – Use the <a href="https://parquet.apache.org/docs/file-format/pageindex/">Parquet page index</a> to skip pages, e.g., in files written by Spark</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/28193"><code class="language-plaintext highlighter-rouge">#28193</code></a> – Improve join ordering for range joins</li>
</ul>

<h3 id="miscellaneous">Miscellaneous</h3>

<ul>
  <li><a href="https://github.com/duckdb/duckdb/pull/27685"><code class="language-plaintext highlighter-rouge">#27685</code></a> – Add the <code class="language-plaintext highlighter-rouge">RETURN_COLUMN_TYPES</code> option to <a href="/docs/2.0/sql/statements/copy.html#copy--to"><code class="language-plaintext highlighter-rouge">COPY ... TO</code></a></li>
  <li><a href="https://github.com/duckdb/duckdb/pull/27969"><code class="language-plaintext highlighter-rouge">#27969</code></a> – Add the <code class="language-plaintext highlighter-rouge">parquet_can_have_nan</code> setting for Parquet files whose statistics do not account for <code class="language-plaintext highlighter-rouge">NaN</code> values</li>
  <li><a href="https://github.com/duckdb/duckdb/pull/28011"><code class="language-plaintext highlighter-rouge">#28011</code></a> – Ship the Windows CLI as ZIP archives for WinGet</li>
</ul>

<h2 id="extensions-and-clients">Extensions and Clients</h2>

<p>As is customary for DuckDB releases, while DuckDB 2.0.1 itself is a patch release, extensions and clients ship new features along with their fixes. Here are some highlights:</p>

<ul>
  <li>The <a href="/docs/2.0/core_extensions/azure.html"><code class="language-plaintext highlighter-rouge">azure</code> extension</a> no longer deletes live data files stored at <code class="language-plaintext highlighter-rouge">abfss://<span class="ge">container</span>@<span class="ge">account</span></code> paths when running <code class="language-plaintext highlighter-rouge">CHECKPOINT</code> on DuckLake (<a href="https://github.com/duckdb/duckdb-azure/pull/211"><code class="language-plaintext highlighter-rouge">duckdb-azure#211</code></a>).</li>
  <li>The experimental <a href="/docs/2.0/core_extensions/glue.html"><code class="language-plaintext highlighter-rouge">glue</code> extension</a> attaches an AWS Glue Data Catalog as a DuckDB database, so you can read and write its Hive tables stored as Parquet, CSV, JSON, or Avro files on S3.</li>
  <li>The <a href="/docs/2.0/core_extensions/iceberg/overview.html"><code class="language-plaintext highlighter-rouge">iceberg</code> extension</a> ships many correctness and performance fixes. For example, TLS now stays enabled when using vended path-style S3 credentials (<a href="https://github.com/duckdb/duckdb-iceberg/pull/1527"><code class="language-plaintext highlighter-rouge">duckdb-iceberg#1527</code></a>). Note that <code class="language-plaintext highlighter-rouge">iceberg_rewrite_data_files</code> now returns Spark's output column names (<a href="https://github.com/duckdb/duckdb-iceberg/pull/1597"><code class="language-plaintext highlighter-rouge">duckdb-iceberg#1597</code></a>).</li>
  <li><a href="https://github.com/duckdb/pg_duckdb"><code class="language-plaintext highlighter-rouge">pg_duckdb</code></a>, the PostgreSQL extension that embeds DuckDB, now publishes binaries for all supported PostgreSQL versions on its <a href="https://github.com/duckdb/pg_duckdb/releases">GitHub releases page</a>. It also ships a number of bugfixes and improves compatibility with other popular PostgreSQL extensions such as Citus and pgvector.</li>
  <li>In the <a href="/docs/2.0/core_extensions/postgres/overview.html"><code class="language-plaintext highlighter-rouge">postgres</code> extension</a>, queries that only touch a single attached PostgreSQL database are now executed entirely in PostgreSQL. If you would like to disable this, run <code class="language-plaintext highlighter-rouge">SET pg_enable_remote_pushdown = false</code> before attaching the database (<a href="https://github.com/duckdb/duckdb-postgres/pull/643"><code class="language-plaintext highlighter-rouge">duckdb-postgres#643</code></a>).</li>
  <li>The <a href="/docs/2.0/clients/python/overview.html">Python client</a> received fixes for several hangs and crashes at exit, including on Python 3.14 (<a href="https://github.com/duckdb/duckdb-python/pull/709"><code class="language-plaintext highlighter-rouge">duckdb-python#709</code></a>, <a href="https://github.com/duckdb/duckdb-python/pull/719"><code class="language-plaintext highlighter-rouge">duckdb-python#719</code></a>). Fetching <code class="language-plaintext highlighter-rouge">TIMESTAMPTZ</code> values no longer requires the <code class="language-plaintext highlighter-rouge">pytz</code> package (<a href="https://github.com/duckdb/duckdb-python/pull/710"><code class="language-plaintext highlighter-rouge">duckdb-python#710</code></a>).</li>
  <li>The <a href="/docs/2.0/core_extensions/aws.html"><code class="language-plaintext highlighter-rouge">aws</code></a> and <a href="/docs/2.0/core_extensions/glue.html"><code class="language-plaintext highlighter-rouge">glue</code></a> extensions are now available in DuckDB-Wasm, and the <a href="/docs/2.0/core_extensions/vortex.html"><code class="language-plaintext highlighter-rouge">vortex</code> extension</a> is now available on Windows.</li>
  <li>The <code class="language-plaintext highlighter-rouge">wasm_mvp</code> platform was discontinued. Core extensions are no longer built for this platform. The remaning Wasm platforms are <code class="language-plaintext highlighter-rouge">wasm_eh</code> for slim deployments and <code class="language-plaintext highlighter-rouge">wasm_threads</code> for enabling threads and SIMD operations.</li>
</ul>

<h2 id="end-of-life-for-duckdb-14-lts">End of Life for DuckDB 1.4 LTS</h2>

<p>Community support for DuckDB 1.4 LTS (Andium) ended on November 17, 2026.
If you are still using it, we recommend upgrading to DuckDB 2.0 LTS, which is supported until at least October 2027.
For details, see the <a href="/release_calendar.html#lts-releases">release calendar</a>.</p>

<h2 id="conclusion">Conclusion</h2>

<p>This post was a short summary of the changes in v2.0.1. As usual, you can find the <a href="https://github.com/duckdb/duckdb/releases/tag/v2.0.1">full release notes on GitHub</a>.
We would like to thank our contributors for providing detailed issue reports and patches.</p>

<p>We are also grateful to the following people whose reports helped us make DuckDB and its extensions more robust and secure:</p>

<ul>
  <li><a href="https://github.com/TristanInSec">@TristanInSec</a> for reporting out-of-bounds reads and a string-length buffer sizing overflow in <code class="language-plaintext highlighter-rouge">DICT_FSST</code> decompression, and for reporting missing validation of Arrow string offsets.</li>
  <li><a href="https://github.com/zerovulnlabs">@zerovulnlabs</a> for reporting missing page-size validation when reading uncompressed Parquet V2 pages.</li>
  <li>zz lin for reporting a problem in the MySQL extension.</li>
</ul>

<p>Stay tuned for <a href="/release_calendar.html">future DuckDB releases</a>, including DuckDB 2.1.0 in the first half of 2027!</p>]]></content>
      

      
        <author>
          <name>The DuckDB team</name>
        </author>
      

      
        
      

      
        <category term="release" />
      

      
      
        <summary type="html"><![CDATA[Today we are releasing DuckDB 2.0.1, the first patch release of our 2.0 LTS line. This release ships bugfixes, performance improvements, and security patches. In addition, a capability is added to define custom extension repositories with only their hostname, and we are shipping Sirius, a new core extension for running DuckDB on NVIDIA GPUs.]]></summary>
      

      
      
        
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://duckdb.org/images/blog/thumbs/duckdb-release-2-0-1.png" />
        <media:content medium="image" url="https://duckdb.org/images/blog/thumbs/duckdb-release-2-0-1.png" xmlns:media="http://search.yahoo.com/mrss/" />
      
    </entry>
  
    <entry>
      

      <title type="html">DuckDB User Group Workshop on AI-Powered Review Analysis with Hugging Face</title>
      <link href="https://duckdb.org/2026/11/17/duckdb-user-group-workshop-ai-powered-review-analysis.html" rel="alternate" type="text/html" title="DuckDB User Group Workshop on AI-Powered Review Analysis with Hugging Face" />
      <published>2026-11-17T00:00:00+00:00</published>
      <updated>2026-11-17T00:00:00+00:00</updated>
      <id>https://duckdb.org/2026/11/17/duckdb-user-group-workshop-ai-powered-review-analysis</id>
      
      
        <content type="html" xml:base="https://duckdb.org/2026/11/17/duckdb-user-group-workshop-ai-powered-review-analysis.html"><![CDATA[<p><img src="/images/blog/duckdb-user-group-workshop-amsterdam.png" alt="Workshop room with attendees at laptops" /></p>

<p>In one afternoon, attendees built a pipeline that finds the products with falling ratings in 2.1 million Amazon reviews and explains why. DuckDB did the filtering and an LLM summarized the complaints. At the end, each attendee had a Hugging Face Space that they can call as an API.</p>

<h2 id="what-we-built">What We Built</h2>

<p>The data was the appliances part of the Amazon Reviews 2023 dataset. That is 2.1 million reviews and about 1.2 GB of raw JSON lines. Nobody downloaded it over the venue Wi-Fi. Attendees built and tested everything on their laptops with a 22 MB sample. Then the same two files ran on Hugging Face against the full data.</p>

<p>The afternoon had five modules.</p>

<ol>
  <li>
    <p><strong>Build locally.</strong> An ingest script converted the sample from JSON lines into two Parquet tables, one for reviews and one for products. It runs in seconds, so attendees could change a column and run it again.</p>
  </li>
  <li>
    <p><strong>Find the trouble.</strong> A file of DuckDB queries, run with <code class="language-plaintext highlighter-rouge">duckdb &lt; sql/analysis.sql</code>, showed the rating distribution, followed one product month by month, ranked products by how much their rating fell in the last six months, and selected the most helpful recent 1 and 2 star reviews for one product.</p>
  </li>
  <li>
    <p><strong>Run it on the full data.</strong> The same ingest script ran as a Hugging Face Job on all 2.1 million reviews. The job read the data inside the Hugging Face network and wrote the Parquet files to a Storage Bucket. The hardware costs $0.01 an hour, and the job ran during the coffee break.</p>
  </li>
  <li>
    <p><strong>Build the workflow.</strong> Gradio's <code class="language-plaintext highlighter-rouge">gr.Workflow</code> showed five Python functions as nodes on a canvas. Attendees connected them and ran them one by one.</p>
  </li>
  <li>
    <p><strong>Ship it.</strong> <code class="language-plaintext highlighter-rouge">gradio deploy</code> put the app on a Hugging Face Space with the bucket mounted at <code class="language-plaintext highlighter-rouge">/data</code>. Each node in the workflow is also an API endpoint that you can call with <code class="language-plaintext highlighter-rouge">gradio_client</code>.</p>
  </li>
</ol>

<p>The rating distribution explains why the ranking query is needed. Most reviews give 5 stars and there is a smaller peak at 1 star, so a plain average does not show change well. The ranking query compares each product's recent average with its earlier average. A simplified version looks like this.</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">WITH</span> <span class="n">split</span> <span class="k">AS</span> <span class="p">(</span>
    <span class="k">SELECT</span>
        <span class="n">parent_asin</span><span class="p">,</span>
        <span class="n">rating</span><span class="p">,</span>
        <span class="n">reviewed_at</span> <span class="o">&gt;=</span> <span class="p">(</span><span class="k">SELECT</span> <span class="nf">max</span><span class="p">(</span><span class="n">reviewed_at</span><span class="p">)</span> <span class="k">FROM</span> <span class="s1">'clean/reviews.parquet'</span><span class="p">)</span>
                       <span class="o">-</span> <span class="nb">INTERVAL</span> <span class="mi">6</span> <span class="k">MONTH</span> <span class="k">AS</span> <span class="n">is_recent</span>
    <span class="k">FROM</span> <span class="s1">'clean/reviews.parquet'</span>
    <span class="k">WHERE</span> <span class="n">verified_purchase</span>
<span class="p">)</span>
<span class="k">SELECT</span>
    <span class="n">parent_asin</span><span class="p">,</span>
    <span class="nf">avg</span><span class="p">(</span><span class="n">rating</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="k">NOT</span> <span class="n">is_recent</span><span class="p">)</span> <span class="k">AS</span> <span class="n">before_avg</span><span class="p">,</span>
    <span class="nf">avg</span><span class="p">(</span><span class="n">rating</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">is_recent</span><span class="p">)</span>     <span class="k">AS</span> <span class="n">recent_avg</span><span class="p">,</span>
    <span class="n">recent_avg</span> <span class="o">-</span> <span class="n">before_avg</span>                  <span class="k">AS</span> <span class="n">change</span>
<span class="k">FROM</span> <span class="n">split</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">parent_asin</span>
<span class="k">HAVING</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">is_recent</span><span class="p">)</span>     <span class="o">&gt;=</span> <span class="mi">20</span>
   <span class="k">AND</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="k">NOT</span> <span class="n">is_recent</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="mi">50</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">change</span>
<span class="k">LIMIT</span> <span class="mi">10</span><span class="p">;</span>
</code></pre></div></div>

<p>A product needs at least 20 recent and 50 earlier verified reviews to be ranked. Attendees changed these two thresholds to see how the list changed.</p>

<h2 id="sql-first-then-the-llm">SQL First, Then the LLM</h2>

<p>DuckDB selects the product with the largest drop in rating and the 40 most helpful recent complaints about it. Only those 40 reviews go to the LLM, which groups them into themes with counts and quotes and lists safety issues first. The Space runs the result, reads its data from a Storage Bucket and makes every step available as an API.</p>

<p>The model does not have to decide which reviews are relevant, because the SQL already did that. This keeps the number of LLM calls small. The pipeline uses six columns: <code class="language-plaintext highlighter-rouge">parent_asin</code>, <code class="language-plaintext highlighter-rouge">rating</code>, <code class="language-plaintext highlighter-rouge">text</code>, <code class="language-plaintext highlighter-rouge">reviewed_at</code>, <code class="language-plaintext highlighter-rouge">helpful_vote</code> and <code class="language-plaintext highlighter-rouge">verified_purchase</code>. If you load other customer feedback into these columns, the SQL and the workflow run without changes.</p>

<h2 id="who-attended">Who Attended</h2>

<p>The workshop brought together software engineers, data engineers, platform engineers, researchers, and product managers from various organizations across Europe. The workshop did not require ML experience — attendees needed to know SQL and be able to read basic Python.</p>

<p>The workshop received an average rating of 4.65 out of 5. Attendees highlighted what worked well: the exercises with real data, the DuckDB and Hugging Face content, the preparation of the speaker and host, the organization and the food.</p>

<h2 id="thanks-and-where-next">Thanks and Where Next?</h2>

<p>Thank you to <a href="https://www.linkedin.com/in/prpatel/">Pratik Patel</a> and Hugging Face for preparing and leading the workshop, and to everyone who attended.</p>

<p><strong>This was the first workshop run by the DuckDB User Group, and we want to run more of them. Join the <a href="https://www.meetup.com/duckdb/">DuckDB User Group on Meetup</a> to stay updated on future workshops and meetups. If your company or community wants to co-organize a DuckDB User Group workshop or meetup, send us a request at <a href="mailto:geertjan@ducklabs.com">geertjan@ducklabs.com</a>. Tell us where you are, what topic you have in mind and what you can offer or need to make it happen, such as a venue, a speaker or catering.</strong></p>]]></content>
      

      
        <author>
          <name>Geertjan Wielenga</name>
        </author>
      

      
        
      

      
        <category term="using-duckdb" />
      

      
      
        <summary type="html"><![CDATA[On 11 November 2026, the DuckDB User Group held its first workshop in Amsterdam, together with Hugging Face. Pratik Patel from Hugging Face led the session.]]></summary>
      

      
      
        
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://duckdb.org/images/blog/thumbs/duckdb-hugging-face-workshop.png" />
        <media:content medium="image" url="https://duckdb.org/images/blog/thumbs/duckdb-hugging-face-workshop.png" xmlns:media="http://search.yahoo.com/mrss/" />
      
    </entry>
  
    <entry>
      

      <title type="html">Local Analytics Doesn’t Need a Database Server</title>
      <link href="https://duckdb.org/2026/11/12/local-analytics-without-a-database-server.html" rel="alternate" type="text/html" title="Local Analytics Doesn’t Need a Database Server" />
      <published>2026-11-12T00:00:00+00:00</published>
      <updated>2026-11-12T00:00:00+00:00</updated>
      <id>https://duckdb.org/2026/11/12/local-analytics-without-a-database-server</id>
      
      
        <content type="html" xml:base="https://duckdb.org/2026/11/12/local-analytics-without-a-database-server.html"><![CDATA[<figure class="quote"><blockquote class="quote-large">
  <p>Quote</p>

  <p>You should own your data. It can live on your computer, not everything has to live in the Cloud. It can be synced via the cloud, but you decide when to keep it local and when not.</p>

  
</blockquote><figcaption class="quote-author"><img src="/images/blog/authors/ilya_boyandin.jpg" alt="" class="avatar" loading="lazy">Ilya Boyandin, creator of <a href="https://sqlrooms.org">SQLRooms</a></figcaption></figure>

<p><a href="https://www.linkedin.com/in/ilyabo/">Ilya Boyandin</a> is a software engineer, the creator of <a href="https://sqlrooms.org">SQLRooms</a>, <a href="https://flowmap.blue">FlowmapBlue</a>, and <a href="https://flowmap.city/">Flowmap City</a>. He worked on geospatial data analytics at Unfolded, the company founded by the team behind the open-source data visualization projects <a href="https://deck.gl">deck.gl</a> and <a href="https://kepler.gl">kepler.gl</a>, which was later acquired by Foursquare.</p>

<h2 id="how-duckdb-entered-the-picture">How DuckDB Entered the Picture</h2>

<p>Ilya first used DuckDB in <a href="https://flowmap.city/">Flowmap City</a>, a side project for <a href="https://ilya.boyandin.me/p/flowmap-city">visualizing mobility flows</a> that he still maintains.
Working with a small budget, Ilya wanted to keep Flowmap City easy to operate with minimal infrastructure. DuckDB’s <a href="/docs/2.0/clients/wasm/overview.html">WebAssembly build</a> lets the app run analytical queries in the user’s browser without a database server. Uploaded datasets are stored as Parquet files in S3. When someone opens a project, the app loads the data into DuckDB-Wasm through <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html">presigned URLs</a>.</p>

<p>As users pan, zoom, or change filters in Flowmap City, DuckDB-Wasm runs SQL queries in the browser to update the map. A single interaction can trigger a number of queries preparing the data for the current viewport:</p>

<div class="video-container">
<video src="https://blobs.duckdb.org/videos/flowmap-city.mp4" controls="" muted="" loop="" playsinline=""></video>
</div>

<p>Ilya explains: <strong>“We can now do much of the analysis and visualization in the browser. This keeps infrastructure requirements low and can be faster because queries don’t need a round trip to the server.”</strong></p>

<h2 id="from-a-side-project-to-sqlrooms">From a Side Project to SQLRooms</h2>

<p>Much of Flowmap City’s data-loading and interface code was useful beyond mobility analysis. Ilya extracted those pieces into SQLRooms, which he continues to develop as an open-source project.</p>

<p><a href="https://sqlrooms.org/">SQLRooms</a> is a modular toolkit for building DuckDB-powered analytics applications in React. It provides building blocks for loading data, writing SQL, displaying tables, creating visualizations, and integrating AI assistants. Developers can combine these pieces with their own components.</p>

<p>These components work together within a <em>Room</em>: a workspace containing datasets, analysis artifacts such as saved queries, charts, maps, and documents, and the application state that connects them. SQLRooms handles query execution through a shared DuckDB connection, so developers can focus on how users explore their data and build on their work.</p>

<p>DuckDB can run directly in the browser through WebAssembly or natively on the user’s machine in a desktop application, allowing data analysis without a remote database server.</p>

<p>Ilya’s interest in local-first software shaped the framework. <strong>“You should own your data. It can live on your computer, not everything has to live in the Cloud. It can be synced via the cloud, but you decide when to keep it local and when not.”</strong></p>

<h2 id="putting-sqlrooms-to-work-at-foursquare">Putting SQLRooms to Work at Foursquare</h2>

<p>At Foursquare, Ilya’s team has been developing <a href="https://ilya.boyandin.me/p/fsq-spatial-desktop">Foursquare Spatial Desktop</a>, a desktop application for exploring geospatial data built with SQLRooms. It combines DuckDB’s analytical engine with <a href="https://kepler.gl/">kepler.gl</a>’s visualization tools. The app builds on the team’s experience with kepler.gl and <a href="https://studio.foursquare.com">Foursquare Studio</a>, its cloud-hosted geospatial analytics platform.</p>

<p>Ilya explains: <strong>“For this particular product, DuckDB embedded into the desktop app is just the perfect fit. It enables analysis workflows which users can execute locally.”</strong> SQLite is embeddable too, he says, but it is not column-oriented and was not designed for analytics on larger datasets.</p>

<p><img src="/images/blog/local-analytics/fsq-spatial-desktop-earthquakes.webp" alt="Foursquare Spatial Desktop" /></p>

<p>Modern laptops have substantial computing power and GPUs well suited to visualization, Ilya adds. <strong>“I’m seeing renewed interest in applications that keep data and computation on the user’s own machine.”</strong></p>

<h3 id="dynamic-tiling-in-spatial-desktop">Dynamic Tiling in Spatial Desktop</h3>

<p>Spatial Desktop uses <a href="https://deck.gl/">deck.gl</a> to render maps, but drawing millions of features at once can slow things down. The app addresses this with dynamic tiling powered by DuckDB’s <a href="/docs/2.0/core_extensions/spatial/overview.html">spatial extension</a>.</p>

<p>Map tiles are often prepared in advance for fast loading. Spatial Desktop can also generate tiles from users’ own datasets on demand, using the local DuckDB database, so users can start exploring without preparing a tileset first. For each requested tile, it selects nearby features and takes a random sample to keep dense tiles manageable. It also simplifies lines and polygons according to the zoom level, retaining more detail as the user zooms in.</p>

<div class="video-container">
<video src="https://blobs.duckdb.org/videos/fsq-spatial-desktop-dynamic-tiling-4-1500.mp4" controls="" muted="" loop="" playsinline=""></video>
</div>

<p>The following simplified query shows the main steps. It assumes the source geometries are already in Web Mercator coordinates (<code class="language-plaintext highlighter-rouge">EPSG:3857</code>). The tile width determines both a small buffer around the search area and a simplification tolerance equivalent to roughly half a pixel:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">WITH</span> <span class="n">tile</span> <span class="k">AS</span> <span class="p">(</span>
    <span class="k">SELECT</span>
        <span class="nf">ST_TileEnvelope</span><span class="p">(</span><span class="ge">z</span><span class="p">,</span> <span class="ge">x</span><span class="p">,</span> <span class="ge">y</span><span class="p">)</span> <span class="k">AS</span> <span class="n">bounds</span><span class="p">,</span>
        <span class="p">(</span><span class="nf">ST_XMax</span><span class="p">(</span><span class="n">bounds</span><span class="p">)</span> <span class="o">-</span> <span class="nf">ST_XMin</span><span class="p">(</span><span class="n">bounds</span><span class="p">))</span> <span class="o">/</span> <span class="mf">256.0</span> <span class="k">AS</span> <span class="n">meters_per_pixel</span>
<span class="p">),</span>
<span class="n">candidates</span> <span class="k">AS</span> <span class="p">(</span>
    <span class="k">SELECT</span>
        <span class="n">f.id</span><span class="p">,</span> <span class="n">f.geometry</span><span class="p">,</span> <span class="n">tile.bounds</span><span class="p">,</span>
        <span class="n">GREATEST</span><span class="p">(</span><span class="n">meters_per_pixel</span> <span class="o">*</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">)</span> <span class="k">AS</span> <span class="n">tolerance</span>
    <span class="k">FROM</span> <span class="n">features</span> <span class="n">f</span><span class="p">,</span> <span class="n">tile</span>
    <span class="k">WHERE</span> <span class="n">ST_Intersects_Extent</span><span class="p">(</span>
        <span class="n">f.geometry</span><span class="p">,</span>
        <span class="nf">ST_Buffer</span><span class="p">(</span><span class="n">tile.bounds</span><span class="p">,</span> <span class="n">meters_per_pixel</span> <span class="o">*</span> <span class="mi">16</span><span class="p">)</span>
    <span class="p">)</span>
<span class="p">),</span>
<span class="n">sampled</span> <span class="k">AS</span> <span class="p">(</span>
    <span class="k">SELECT</span> <span class="o">*</span>
    <span class="k">FROM</span> <span class="n">candidates</span>
    <span class="k">USING</span> <span class="k">SAMPLE</span> <span class="nf">reservoir</span><span class="p">(</span><span class="mi">50000</span> <span class="k">ROWS</span><span class="p">)</span>
<span class="p">),</span>
<span class="n">encoded</span> <span class="k">AS</span> <span class="p">(</span>
    <span class="k">SELECT</span>
        <span class="n">id</span><span class="p">,</span>
        <span class="nf">ST_AsMVTGeom</span><span class="p">(</span>
            <span class="nf">ST_SimplifyPreserveTopology</span><span class="p">(</span><span class="n">geometry</span><span class="p">,</span> <span class="n">tolerance</span><span class="p">),</span>
            <span class="nf">ST_Extent</span><span class="p">(</span><span class="n">bounds</span><span class="p">)</span>
        <span class="p">)</span> <span class="k">AS</span> <span class="n">geom</span>
    <span class="k">FROM</span> <span class="n">sampled</span>
<span class="p">)</span>
<span class="k">SELECT</span> <span class="nf">ST_AsMVT</span><span class="p">(</span><span class="n">encoded</span><span class="p">,</span> <span class="s1">'features'</span><span class="p">)</span> <span class="k">AS</span> <span class="n">tile</span>
<span class="k">FROM</span> <span class="n">encoded</span>
<span class="k">WHERE</span> <span class="n">geom</span> <span class="k">IS</span> <span class="k">NOT</span> <span class="nb">NULL</span><span class="p">;</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">ST_AsMVTGeom</code> converts the simplified geometries to tile coordinates and clips them; <a href="/docs/2.0/core_extensions/spatial/functions.html#st_asmvt"><code class="language-plaintext highlighter-rouge">ST_AsMVT</code></a> packages them and their attributes into a Mapbox Vector Tile (MVT). The production implementation also handles invalid geometries, filters out very small lines and polygons, and caches generated tiles.</p>

<p>An HTTP server running locally as part of the Electron desktop app serves the tiles requested by the map.</p>

<h2 id="graph-analytics-on-the-fly-with-cosmograph">Graph Analytics on the Fly with Cosmograph</h2>

<p>SQLRooms also powers the analytical workspace in <a href="https://cosmograph.app">Cosmograph</a>, a browser-based graph exploration tool developed by <a href="https://rokotyan.com/">Nikita Rokotyan</a> and Thor Whalen. Ilya helped integrate SQLRooms into the application, which can visualize graphs with millions of edges.</p>

<div class="video-container">
<video src="https://blobs.duckdb.org/videos/cosmograph-2.0.mp4" controls="" muted="" loop="" playsinline=""></video>
</div>

<p>Cosmograph has been tested with datasets ranging from tens of thousands of points to several million. DuckDB-Wasm handles data loading and SQL queries in a background worker, helping keep the interface responsive. It lets the app filter and summarize data as users explore, while columnar query results reduce the conversion work needed to prepare data for visualization.</p>

<h2 id="when-the-agent-writes-the-sql">When the Agent Writes the SQL</h2>

<p>SQLRooms also supports AI-assisted analysis. <strong>“The combination of SQL and AI agents is actually quite powerful,”</strong> Ilya says. <strong>“SQL has a long history, there are many documents on the web explaining how to use it, so LLMs are pretty good at generating it.”</strong></p>

<p>Users can ask questions in natural language. The assistant generates SQL queries and chart specifications, which the application executes and renders locally. The source dataset can stay on the user’s machine, while database schemas and selected query results can be shared with the AI provider to help answer questions.</p>

<p>In the Spatial Desktop example below, the assistant generates SQL to retrieve data from available sources and calculate a combined score for wine-growing suitability across Italy. The resulting map is accompanied by AI-generated regional analysis:</p>

<p><img src="/images/blog/local-analytics/italy-wine-suitability-with-sidebar.webp" alt="Foursquare Spatial Desktop showing a wine-growing suitability map of Italy alongside AI-generated regional analysis" /></p>

<h2 id="where-sqlrooms-goes-next">Where SQLRooms Goes Next</h2>

<p>Ilya is extending SQLRooms’ workspace model so users can bring their analysis together in interactive documents. These documents combine text with blocks such as charts or SQL queries, letting users explain their findings alongside the analysis that produced them.</p>

<div class="video-container">
<video src="https://blobs.duckdb.org/videos/sqlrooms-cars-document.mp4" controls="" muted="" loop="" playsinline=""></video>
</div>

<p>Ilya is also exploring other ways to work with these analytical projects. At <a href="/events/2026/06/24/duckcon7/">DuckCon #7</a> in Amsterdam, he demonstrated a SQLRooms command-line tool with a notebook-style interface. It saves both the data and the analysis artifacts in a single DuckDB database file. The goal is to let users continue the same project through a graphical application or the command line. The CLI design is still evolving.</p>

<h2 id="learn-more">Learn More</h2>

<p>Ilya’s <a href="https://www.youtube.com/watch?v=fV1LXnPl4ng">five-minute talk</a> from DuckCon #7 gives a short tour of this direction.</p>

<div class="video-container">
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/fV1LXnPl4ng" title="YouTube video player" frameborder="0" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen=""></iframe>
</div>

<p>SQLRooms is open source and available at <a href="https://sqlrooms.org">sqlrooms.org</a>. Its <a href="https://sqlrooms.org/examples">examples page</a> is a good place to start. <a href="https://flowmap.city/">Flowmap City</a>, <a href="https://foursquare.com/products/spatial-desktop/">Foursquare Spatial Desktop</a>, and <a href="https://cosmograph.app">Cosmograph</a> are free to try.</p>

<p>We would like to thank Ilya for the conversation. You can follow his writing on DuckDB and SQLRooms on <a href="https://ilya.boyandin.me/">his website</a>. And if you are reading this, are using DuckDB, and would like to share your story, drop us a line at <a href="mailto:geertjan@ducklabs.com">geertjan@ducklabs.com</a>.</p>]]></content>
      

      
        <author>
          <name>Ilya Boyandin</name>
        </author>
      
        <author>
          <name>Geertjan Wielenga</name>
        </author>
      
        <author>
          <name>Tim Cox</name>
        </author>
      

      
        
      

      
        <category term="case-study" />
      

      
      
        <summary type="html"><![CDATA[From interactive maps to graph exploration, DuckDB makes it possible to analyze data without a database server. Ilya Boyandin shares how this approach led to SQLRooms, a toolkit for building analytics applications that bring data, visualizations, and AI-assisted analysis together on the user’s machine.]]></summary>
      

      
      
        
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://duckdb.org/images/blog/thumbs/local-analytics-without-a-database-server.png" />
        <media:content medium="image" url="https://duckdb.org/images/blog/thumbs/local-analytics-without-a-database-server.png" xmlns:media="http://search.yahoo.com/mrss/" />
      
    </entry>
  
    <entry>
      

      <title type="html">Ducks in a Column</title>
      <link href="https://duckdb.org/2026/11/10/ducks-in-a-column.html" rel="alternate" type="text/html" title="Ducks in a Column" />
      <published>2026-11-10T00:00:00+00:00</published>
      <updated>2026-11-10T00:00:00+00:00</updated>
      <id>https://duckdb.org/2026/11/10/ducks-in-a-column</id>
      
      
        <content type="html" xml:base="https://duckdb.org/2026/11/10/ducks-in-a-column.html"><![CDATA[<h2 id="why-columns">Why Columns?</h2>

<p>DuckDB stores each column separately instead of storing each row as one record. A query that touches three columns out of fifty reads only those three.</p>

<p>That design choice explains many of DuckDB’s performance features. Columnar storage <a href="/2022/10/28/lightweight-compression.html">compresses well</a> because a column holds values of one type, and those values often repeat. The engine processes each column in vectors of 2,048 values at a time. And a query that asks for fewer columns does less work.</p>

<p>The examples in this post use a sample dataset of 400 ducks, each marked with a numbered leg band (a ring) and seen at one of four ponds between October 2025 and April 2026. The <code class="language-plaintext highlighter-rouge">sightings</code> table has five columns: <code class="language-plaintext highlighter-rouge">ring_id</code>, <code class="language-plaintext highlighter-rouge">pond</code>, <code class="language-plaintext highlighter-rouge">species</code>, <code class="language-plaintext highlighter-rouge">weight_g</code>, and <code class="language-plaintext highlighter-rouge">seen_at</code>.</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="o">*</span> <span class="k">FROM</span> <span class="n">sightings</span> <span class="k">LIMIT</span> <span class="mi">3</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌─────────┬───────┬─────────┬──────────┬─────────────────────┐
│ ring_id │ pond  │ species │ weight_g │       seen_at       │
├─────────┼───────┼─────────┼──────────┼─────────────────────┤
│ R0001   │ south │ wigeon  │ 862      │ 2025-11-06 12:18:38 │
│ R0002   │ south │ wigeon  │ 578      │ 2025-12-04 00:12:54 │
│ R0003   │ south │ wigeon  │ 734      │ 2026-01-06 16:50:41 │
└─────────┴───────┴─────────┴──────────┴─────────────────────┘
</code></pre></div></div>

<p>Every example runs in the DuckDB CLI or from Python with <code class="language-plaintext highlighter-rouge">duckdb.sql(...)</code>.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">pip </span>install <span class="nb">duckdb</span>                        <span class="c"># Python</span>
<span class="nb">curl </span>https://install.duckdb.org | <span class="nb">bash</span>    <span class="c"># CLI</span>
</code></pre></div></div>

<h2 id="querying-files-in-place">Querying Files in Place</h2>

<p>You don’t need to load data before you query it. DuckDB treats a file path as a table and infers column names and types from the file.</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="o">*</span> <span class="k">FROM</span> <span class="s1">'ponds.csv'</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌─────────┬───────┬─────────┐
│ pond_id │ pond  │ area_m2 │
├─────────┼───────┼─────────┤
│ 0007    │ north │ 4200    │
│ 0042    │ south │ 1800    │
│ 0113    │ mill  │ 950     │
│ 0256    │ reed  │ 3100    │
└─────────┴───────┴─────────┘
</code></pre></div></div>

<p>A glob pattern queries a whole folder of Parquet files. With <code class="language-plaintext highlighter-rouge">filename = true</code>, DuckDB adds the file name as a column:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">filename</span><span class="p">,</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="n">sightings</span>
<span class="k">FROM</span> <span class="nf">read_parquet</span><span class="p">(</span><span class="s1">'sightings/*.parquet'</span><span class="p">,</span> <span class="k">filename</span> <span class="o">=</span> <span class="k">true</span><span class="p">)</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="k">ALL</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="k">ALL</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌────────────────────────┬───────────┐
│        filename        │ sightings │
├────────────────────────┼───────────┤
│ sightings/2025.parquet │ 184       │
│ sightings/2026.parquet │ 216       │
└────────────────────────┴───────────┘
</code></pre></div></div>

<p>DuckDB can also read remote files over <a href="/docs/2.0/core_extensions/httpfs/https.html">HTTPS</a> or <a href="/docs/2.0/core_extensions/httpfs/s3api.html">S3</a>. The <a href="/docs/2.0/core_extensions/httpfs/overview.html">httpfs extension</a> loads automatically when you use these paths:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="o">*</span> <span class="k">FROM</span> <span class="s1">'s3://wetlands/2026/*.parquet'</span><span class="p">;</span>
</code></pre></div></div>

<p>The <a href="/docs/2.0/data/parquet/overview.html">Parquet file format</a> also stores data by column. DuckDB reads only the columns your query names. Parquet also stores min and max statistics for each row group, so DuckDB can skip row groups whose statistics rule out a filter (<a href="/docs/2.0/guides/performance/indexing.html#zonemaps">zonemaps</a>).</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">species</span><span class="p">,</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="n">sightings</span>
<span class="k">FROM</span> <span class="s1">'sightings/*.parquet'</span>
<span class="k">WHERE</span> <span class="n">seen_at</span> <span class="o">&gt;=</span> <span class="nb">DATE</span> <span class="s1">'2026-01-01'</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="k">ALL</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="k">ALL</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌─────────┬───────────┐
│ species │ sightings │
├─────────┼───────────┤
│ mallard │ 89        │
│ pintail │ 29        │
│ teal    │ 37        │
│ tufted  │ 29        │
│ wigeon  │ 32        │
└─────────┴───────────┘
</code></pre></div></div>

<blockquote>
  <p>Tip <strong>Check the sniffer’s work.</strong> When a CSV loads with unexpected types, ask DuckDB what it guessed. Then pin the types you need.</p>
</blockquote>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">DESCRIBE</span> <span class="k">SELECT</span> <span class="o">*</span> <span class="k">FROM</span> <span class="s1">'ponds.csv'</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌─────────────┬─────────────┬──────┬──────┬─────────┬───────┐
│ column_name │ column_type │ null │ key  │ default │ extra │
├─────────────┼─────────────┼──────┼──────┼─────────┼───────┤
│ pond_id     │ VARCHAR     │ YES  │ NULL │ NULL    │ NULL  │
│ pond        │ VARCHAR     │ YES  │ NULL │ NULL    │ NULL  │
│ area_m2     │ BIGINT      │ YES  │ NULL │ NULL    │ NULL  │
└─────────────┴─────────────┴──────┴──────┴─────────┴───────┘
</code></pre></div></div>

<p>The sniffer keeps <code class="language-plaintext highlighter-rouge">pond_id</code> as text, so the leading zeros survive. To override a guess, pass the type explicitly:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="o">*</span> <span class="k">FROM</span> <span class="nf">read_csv</span><span class="p">(</span><span class="s1">'ponds.csv'</span><span class="p">,</span> <span class="k">types</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'area_m2'</span><span class="p">:</span> <span class="s1">'DOUBLE'</span><span class="p">});</span>
</code></pre></div></div>

<blockquote>
  <p>Tip <strong>Hive partitions become columns.</strong> A path like <code class="language-plaintext highlighter-rouge">year=2026/pond=north/</code> turns into <code class="language-plaintext highlighter-rouge">year</code> and <code class="language-plaintext highlighter-rouge">pond</code> columns, and filters on them skip folders entirely. The next section creates this layout.</p>
</blockquote>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span>
<span class="k">FROM</span> <span class="nf">read_parquet</span><span class="p">(</span><span class="s1">'lake/*/*/*.parquet'</span><span class="p">,</span> <span class="k">hive_partitioning</span> <span class="o">=</span> <span class="k">true</span><span class="p">)</span>
<span class="k">WHERE</span> <span class="n">year</span> <span class="o">=</span> <span class="mi">2026</span> <span class="k">AND</span> <span class="n">pond</span> <span class="o">=</span> <span class="s1">'north'</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌──────────────┐
│ count_star() │
├──────────────┤
│ 58           │
└──────────────┘
</code></pre></div></div>

<h2 id="column-level-sql">Column-Level SQL</h2>

<p>DuckDB’s <a href="/docs/2.0/sql/dialect/friendly_sql.html">friendly SQL</a> lets you select, exclude, and transform columns in bulk. On wide tables, this saves typing and keeps queries readable.</p>

<p><strong>Drop columns with <code class="language-plaintext highlighter-rouge">EXCLUDE</code>, or rewrite them in place with <code class="language-plaintext highlighter-rouge">REPLACE</code>.</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="o">*</span> <span class="k">EXCLUDE</span> <span class="p">(</span><span class="n">ring_id</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">sightings</span> <span class="k">LIMIT</span> <span class="mi">3</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌───────┬─────────┬──────────┬─────────────────────┐
│ pond  │ species │ weight_g │       seen_at       │
├───────┼─────────┼──────────┼─────────────────────┤
│ south │ wigeon  │ 862      │ 2025-11-06 12:18:38 │
│ south │ wigeon  │ 578      │ 2025-12-04 00:12:54 │
│ south │ wigeon  │ 734      │ 2026-01-06 16:50:41 │
└───────┴─────────┴──────────┴─────────────────────┘
</code></pre></div></div>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="o">*</span> <span class="k">REPLACE</span> <span class="p">(</span><span class="nf">upper</span><span class="p">(</span><span class="n">species</span><span class="p">)</span> <span class="k">AS</span> <span class="n">species</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">sightings</span> <span class="k">LIMIT</span> <span class="mi">3</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌─────────┬───────┬─────────┬──────────┬─────────────────────┐
│ ring_id │ pond  │ species │ weight_g │       seen_at       │
├─────────┼───────┼─────────┼──────────┼─────────────────────┤
│ R0001   │ south │ WIGEON  │ 862      │ 2025-11-06 12:18:38 │
│ R0002   │ south │ WIGEON  │ 578      │ 2025-12-04 00:12:54 │
│ R0003   │ south │ WIGEON  │ 734      │ 2026-01-06 16:50:41 │
└─────────┴───────┴─────────┴──────────┴─────────────────────┘
</code></pre></div></div>

<p><strong>Select columns by pattern with <code class="language-plaintext highlighter-rouge">COLUMNS()</code>.</strong> It takes a regular expression, a list of names, or a lambda, and applies an expression to every matching column. The <code class="language-plaintext highlighter-rouge">pond_readings</code> table has three temperature columns, so this query returns the highest reading for each:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="nf">max</span><span class="p">(</span><span class="k">COLUMNS</span><span class="p">(</span><span class="s1">'^temp_'</span><span class="p">))</span> <span class="k">FROM</span> <span class="n">pond_readings</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌────────────────┬─────────────┬────────────────┐
│ temp_morning_c │ temp_noon_c │ temp_evening_c │
├────────────────┼─────────────┼────────────────┤
│ 8.0            │ 13.7        │ 8.3            │
└────────────────┴─────────────┴────────────────┘
</code></pre></div></div>

<p>The same pattern handles missing values. This query replaces each <code class="language-plaintext highlighter-rouge">NULL</code> with <code class="language-plaintext highlighter-rouge">0</code> in every column whose name ends in <code class="language-plaintext highlighter-rouge">_count</code>:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="nf">coalesce</span><span class="p">(</span><span class="k">COLUMNS</span><span class="p">(</span><span class="k">lambda</span> <span class="n">c</span><span class="p">:</span> <span class="n">c</span> <span class="k">LIKE</span> <span class="s1">'%_count'</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span>
<span class="k">FROM</span> <span class="n">counts</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌───────────────┬────────────┬──────────────┐
│ mallard_count │ teal_count │ wigeon_count │
├───────────────┼────────────┼──────────────┤
│ 12            │ 0          │ 3            │
│ 0             │ 4          │ 1            │
│ 7             │ 2          │ 0            │
│ 0             │ 0          │ 5            │
└───────────────┴────────────┴──────────────┘
</code></pre></div></div>

<p>You can rename matching columns as you select them. In the replacement, <code class="language-plaintext highlighter-rouge">\1</code> refers to the first capture group:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="k">COLUMNS</span><span class="p">(</span><span class="s1">'temp_(.*)_c'</span><span class="p">)</span> <span class="k">AS</span> <span class="s1">'\1_celsius'</span>
<span class="k">FROM</span> <span class="n">pond_readings</span>
<span class="k">LIMIT</span> <span class="mi">3</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌─────────────────┬──────────────┬─────────────────┐
│ morning_celsius │ noon_celsius │ evening_celsius │
├─────────────────┼──────────────┼─────────────────┤
│ 6.3             │ 9.1          │ 8.0             │
│ 6.9             │ 10.7         │ 6.6             │
│ 7.8             │ 8.8          │ 7.9             │
└─────────────────┴──────────────┴─────────────────┘
</code></pre></div></div>

<p><strong>Start with <code class="language-plaintext highlighter-rouge">FROM</code>.</strong> You can lead with the table and leave out <code class="language-plaintext highlighter-rouge">SELECT</code>. <code class="language-plaintext highlighter-rouge">FROM sightings;</code> alone is the same as <code class="language-plaintext highlighter-rouge">SELECT * FROM sightings;</code>.</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">FROM</span> <span class="n">sightings</span> <span class="k">SELECT</span> <span class="n">species</span><span class="p">,</span> <span class="n">pond</span> <span class="k">LIMIT</span> <span class="mi">3</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌─────────┬───────┐
│ species │ pond  │
├─────────┼───────┤
│ wigeon  │ south │
│ wigeon  │ south │
│ wigeon  │ south │
└─────────┴───────┘
</code></pre></div></div>

<p><strong>Pack columns into a <code class="language-plaintext highlighter-rouge">STRUCT</code>.</strong> A struct is a single column with named fields. Unpack one with <code class="language-plaintext highlighter-rouge">.*</code> to turn its fields back into top-level columns:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">sighting</span><span class="p">.</span><span class="o">*</span> <span class="k">FROM</span> <span class="p">(</span>
    <span class="k">SELECT</span> <span class="p">{</span><span class="s1">'species'</span><span class="p">:</span> <span class="n">species</span><span class="p">,</span> <span class="s1">'pond'</span><span class="p">:</span> <span class="n">pond</span><span class="p">}</span> <span class="k">AS</span> <span class="n">sighting</span> <span class="k">FROM</span> <span class="n">sightings</span>
<span class="p">)</span>
<span class="k">LIMIT</span> <span class="mi">3</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌─────────┬───────┐
│ species │ pond  │
├─────────┼───────┤
│ wigeon  │ south │
│ wigeon  │ south │
│ wigeon  │ south │
└─────────┴───────┘
</code></pre></div></div>

<blockquote>
  <p>Tip <strong>Let DuckDB profile the columns.</strong> <code class="language-plaintext highlighter-rouge">SUMMARIZE</code> returns one row per column, with its type, min, max, approximate distinct count, null percentage, and quartiles.</p>
</blockquote>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SUMMARIZE</span> <span class="n">sightings</span><span class="p">;</span>
<span class="k">SUMMARIZE</span> <span class="k">SELECT</span> <span class="o">*</span> <span class="k">FROM</span> <span class="s1">'sightings/*.parquet'</span><span class="p">;</span>
</code></pre></div></div>

<h2 id="aggregation-shortcuts">Aggregation Shortcuts</h2>

<p>Aggregates benefit from columnar storage because summing a column means scanning one column of values. DuckDB adds syntax that keeps the SQL as short as the work.</p>

<p><strong><a href="/docs/2.0/sql/query_syntax/groupby.html#group-by-all"><code class="language-plaintext highlighter-rouge">GROUP BY ALL</code></a> groups by every non-aggregated column in the <code class="language-plaintext highlighter-rouge">SELECT</code> clause, so you don’t repeat the list.</strong></p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">pond</span><span class="p">,</span> <span class="n">species</span><span class="p">,</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="n">sightings</span><span class="p">,</span> <span class="nf">round</span><span class="p">(</span><span class="nf">avg</span><span class="p">(</span><span class="n">weight_g</span><span class="p">))</span> <span class="k">AS</span> <span class="n">avg_weight_g</span>
<span class="k">FROM</span> <span class="n">sightings</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="k">ALL</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="k">ALL</span>
<span class="k">LIMIT</span> <span class="mi">5</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌──────┬─────────┬───────────┬──────────────┐
│ pond │ species │ sightings │ avg_weight_g │
├──────┼─────────┼───────────┼──────────────┤
│ mill │ mallard │ 46        │ 1110.0       │
│ mill │ pintail │ 11        │ 910.0        │
│ mill │ teal    │ 15        │ 352.0        │
│ mill │ tufted  │ 10        │ 879.0        │
│ mill │ wigeon  │ 14        │ 720.0        │
└──────┴─────────┴───────────┴──────────────┘
</code></pre></div></div>

<p><strong><code class="language-plaintext highlighter-rouge">FILTER</code> counts several categories in one pass,</strong> instead of running one query per category:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span>
    <span class="n">pond</span><span class="p">,</span>
    <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">species</span> <span class="o">=</span> <span class="s1">'mallard'</span><span class="p">)</span> <span class="k">AS</span> <span class="n">mallards</span><span class="p">,</span>
    <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">species</span> <span class="o">=</span> <span class="s1">'teal'</span><span class="p">)</span>    <span class="k">AS</span> <span class="n">teals</span><span class="p">,</span>
    <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FILTER</span> <span class="p">(</span><span class="k">WHERE</span> <span class="n">weight_g</span> <span class="o">&gt;</span> <span class="mi">1200</span><span class="p">)</span>     <span class="k">AS</span> <span class="n">heavyweights</span>
<span class="k">FROM</span> <span class="n">sightings</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="k">ALL</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="k">ALL</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌───────┬──────────┬───────┬──────────────┐
│ pond  │ mallards │ teals │ heavyweights │
├───────┼──────────┼───────┼──────────────┤
│ mill  │ 46       │ 15    │ 16           │
│ north │ 48       │ 17    │ 12           │
│ reed  │ 26       │ 14    │ 6            │
│ south │ 48       │ 19    │ 16           │
└───────┴──────────┴───────┴──────────────┘
</code></pre></div></div>

<p><strong><code class="language-plaintext highlighter-rouge">arg_max</code> returns the value from the row with the largest value of another column,</strong> so you don’t need a self-join. Here it finds the species of the heaviest bird at each pond:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">pond</span><span class="p">,</span>
       <span class="nf">arg_max</span><span class="p">(</span><span class="n">species</span><span class="p">,</span> <span class="n">weight_g</span><span class="p">)</span> <span class="k">AS</span> <span class="n">heaviest_species</span><span class="p">,</span>
       <span class="nf">max</span><span class="p">(</span><span class="n">weight_g</span><span class="p">)</span> <span class="k">AS</span> <span class="n">max_weight_g</span>
<span class="k">FROM</span> <span class="n">sightings</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="k">ALL</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="k">ALL</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌───────┬──────────────────┬──────────────┐
│ pond  │ heaviest_species │ max_weight_g │
├───────┼──────────────────┼──────────────┤
│ mill  │ mallard          │ 1358         │
│ north │ mallard          │ 1359         │
│ reed  │ mallard          │ 1312         │
│ south │ mallard          │ 1357         │
└───────┴──────────────────┴──────────────┘
</code></pre></div></div>

<p><strong><code class="language-plaintext highlighter-rouge">PIVOT</code> and <code class="language-plaintext highlighter-rouge">UNPIVOT</code> turn rows into columns and back.</strong> <code class="language-plaintext highlighter-rouge">PIVOT</code> makes one column per distinct value, here one column per species:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">PIVOT</span> <span class="n">sightings</span> <span class="k">ON</span> <span class="n">species</span> <span class="k">USING</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">GROUP</span> <span class="k">BY</span> <span class="n">pond</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">pond</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌───────┬─────────┬─────────┬──────┬────────┬────────┐
│ pond  │ mallard │ pintail │ teal │ tufted │ wigeon │
├───────┼─────────┼─────────┼──────┼────────┼────────┤
│ mill  │ 46      │ 11      │ 15   │ 10     │ 14     │
│ north │ 48      │ 19      │ 17   │ 16     │ 17     │
│ reed  │ 26      │ 11      │ 14   │ 13     │ 16     │
│ south │ 48      │ 11      │ 19   │ 14     │ 15     │
└───────┴─────────┴─────────┴──────┴────────┴────────┘
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">UNPIVOT</code> goes the other way. The <code class="language-plaintext highlighter-rouge">monthly_counts</code> table has one column per month, so this query turns those columns back into rows:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="o">*</span> <span class="k">FROM</span> <span class="p">(</span>
    <span class="k">UNPIVOT</span> <span class="n">monthly_counts</span>
    <span class="k">ON</span> <span class="k">COLUMNS</span><span class="p">(</span><span class="o">*</span> <span class="k">EXCLUDE</span> <span class="n">pond</span><span class="p">)</span>
    <span class="k">INTO</span> <span class="k">NAME</span> <span class="n">month</span> <span class="k">VALUE</span> <span class="n">sightings</span>
<span class="p">)</span>
<span class="k">WHERE</span> <span class="n">pond</span> <span class="o">=</span> <span class="s1">'north'</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌───────┬───────┬───────────┐
│ pond  │ month │ sightings │
├───────┼───────┼───────────┤
│ north │ Apr   │ 6         │
│ north │ Dec   │ 18        │
│ north │ Feb   │ 14        │
│ north │ Jan   │ 21        │
│ north │ Mar   │ 17        │
│ north │ Nov   │ 20        │
│ north │ Oct   │ 21        │
└───────┴───────┴───────────┘
</code></pre></div></div>

<blockquote>
  <p>Tip <strong>Approximate when exact is expensive.</strong> On billions of rows, <code class="language-plaintext highlighter-rouge">approx_count_distinct</code> and <code class="language-plaintext highlighter-rouge">approx_quantile</code> use a fraction of the memory of their exact counterparts. On this small table, the estimate of 404 distinct rings is close to the exact count of 400.</p>
</blockquote>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="nf">approx_count_distinct</span><span class="p">(</span><span class="n">ring_id</span><span class="p">),</span> <span class="nf">approx_quantile</span><span class="p">(</span><span class="n">weight_g</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">)</span>
<span class="k">FROM</span> <span class="n">sightings</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌────────────────────────────────┬────────────────────────────────┐
│ approx_count_distinct(ring_id) │ approx_quantile(weight_g, 0.9) │
├────────────────────────────────┼────────────────────────────────┤
│ 404                            │ 1236                           │
└────────────────────────────────┴────────────────────────────────┘
</code></pre></div></div>

<h2 id="window-functions-and-asof-joins">Window Functions and ASOF Joins</h2>

<p>Window functions compute over neighboring rows without collapsing them. The <code class="language-plaintext highlighter-rouge">daily_counts</code> table has one row per pond per day, including days with no sightings. This query shows the day-over-day change and a rolling seven-day average:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span>
    <span class="n">pond</span><span class="p">,</span>
    <span class="n">seen_at</span><span class="p">,</span>
    <span class="n">ducks</span><span class="p">,</span>
    <span class="n">ducks</span> <span class="o">-</span> <span class="nf">lag</span><span class="p">(</span><span class="n">ducks</span><span class="p">)</span> <span class="k">OVER</span> <span class="n">w</span>                      <span class="k">AS</span> <span class="n">change</span><span class="p">,</span>
    <span class="nf">round</span><span class="p">(</span><span class="nf">avg</span><span class="p">(</span><span class="n">ducks</span><span class="p">)</span> <span class="k">OVER</span> <span class="p">(</span><span class="n">w</span> <span class="k">ROWS</span> <span class="mi">6</span> <span class="k">PRECEDING</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span> <span class="k">AS</span> <span class="n">rolling_7</span>
<span class="k">FROM</span> <span class="n">daily_counts</span>
<span class="k">WINDOW</span> <span class="n">w</span> <span class="k">AS</span> <span class="p">(</span><span class="k">PARTITION</span> <span class="k">BY</span> <span class="n">pond</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">seen_at</span><span class="p">)</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">pond</span><span class="p">,</span> <span class="n">seen_at</span>
<span class="k">LIMIT</span> <span class="mi">8</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌──────┬────────────┬───────┬────────┬───────────┐
│ pond │  seen_at   │ ducks │ change │ rolling_7 │
├──────┼────────────┼───────┼────────┼───────────┤
│ mill │ 2025-10-01 │ 0     │ NULL   │ 0.0       │
│ mill │ 2025-10-02 │ 0     │ 0      │ 0.0       │
│ mill │ 2025-10-03 │ 0     │ 0      │ 0.0       │
│ mill │ 2025-10-04 │ 1     │ 1      │ 0.25      │
│ mill │ 2025-10-05 │ 0     │ -1     │ 0.2       │
│ mill │ 2025-10-06 │ 0     │ 0      │ 0.17      │
│ mill │ 2025-10-07 │ 0     │ 0      │ 0.14      │
│ mill │ 2025-10-08 │ 2     │ 2      │ 0.43      │
└──────┴────────────┴───────┴────────┴───────────┘
</code></pre></div></div>

<p><strong><code class="language-plaintext highlighter-rouge">QUALIFY</code> filters on a window function directly,</strong> so finding the latest sighting at each pond doesn’t need a subquery:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">pond</span><span class="p">,</span> <span class="n">ring_id</span><span class="p">,</span> <span class="n">species</span><span class="p">,</span> <span class="n">seen_at</span>
<span class="k">FROM</span> <span class="n">sightings</span>
<span class="k">QUALIFY</span> <span class="nf">row_number</span><span class="p">()</span> <span class="k">OVER</span> <span class="p">(</span><span class="k">PARTITION</span> <span class="k">BY</span> <span class="n">pond</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">seen_at</span> <span class="k">DESC</span><span class="p">)</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">pond</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌───────┬─────────┬─────────┬─────────────────────┐
│ pond  │ ring_id │ species │       seen_at       │
├───────┼─────────┼─────────┼─────────────────────┤
│ mill  │ R0015   │ mallard │ 2026-04-18 18:17:29 │
│ north │ R0077   │ mallard │ 2026-04-14 09:02:03 │
│ reed  │ R0044   │ teal    │ 2026-04-18 21:44:23 │
│ south │ R0045   │ wigeon  │ 2026-04-11 16:29:40 │
└───────┴─────────┴─────────┴─────────────────────┘
</code></pre></div></div>

<p><strong><a href="/2023/09/15/asof-joins-fuzzy-temporal-lookups.html"><code class="language-plaintext highlighter-rouge">ASOF JOIN</code></a> matches each row to the nearest earlier row in another table.</strong> It’s the right tool when two time series never share exact timestamps, such as sightings and weather readings. The <code class="language-plaintext highlighter-rouge">weather</code> table has a reading every six hours at each pond. This query attaches the most recent reading to each sighting:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">s.ring_id</span><span class="p">,</span> <span class="n">s.seen_at</span><span class="p">,</span> <span class="n">w.temp_c</span><span class="p">,</span> <span class="n">w.wind_kmh</span>
<span class="k">FROM</span> <span class="n">sightings</span> <span class="n">s</span>
<span class="k">ASOF</span> <span class="k">JOIN</span> <span class="n">weather</span> <span class="n">w</span>
  <span class="k">ON</span> <span class="n">s.pond</span> <span class="o">=</span> <span class="n">w.pond</span>
 <span class="k">AND</span> <span class="n">s.seen_at</span> <span class="o">&gt;=</span> <span class="n">w.read_at</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">s.seen_at</span>
<span class="k">LIMIT</span> <span class="mi">5</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌─────────┬─────────────────────┬────────┬──────────┐
│ ring_id │       seen_at       │ temp_c │ wind_kmh │
├─────────┼─────────────────────┼────────┼──────────┤
│ R0096   │ 2025-10-01 03:52:49 │ 10.1   │ 20.0     │
│ R0109   │ 2025-10-01 09:11:24 │ 9.3    │ 33.3     │
│ R0215   │ 2025-10-01 10:59:02 │ 9.2    │ 31.8     │
│ R0315   │ 2025-10-01 20:44:16 │ 10.4   │ 26.4     │
│ R0076   │ 2025-10-01 21:17:05 │ 10.4   │ 26.4     │
└─────────┴─────────────────────┴────────┴──────────┘
</code></pre></div></div>

<blockquote>
  <p>Tip <strong>Lists stay in one column.</strong> <code class="language-plaintext highlighter-rouge">list()</code> gathers a group into a single array value, and list functions work on that array without unnesting it.</p>
</blockquote>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span> <span class="n">pond</span><span class="p">,</span>
       <span class="nf">list</span><span class="p">(</span><span class="n">ring_id</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">seen_at</span><span class="p">)[</span><span class="mi">1</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span> <span class="k">AS</span> <span class="n">first_three_rings</span><span class="p">,</span>
       <span class="nf">len</span><span class="p">(</span><span class="nf">list</span><span class="p">(</span><span class="n">ring_id</span><span class="p">))</span>                  <span class="k">AS</span> <span class="n">sightings</span>
<span class="k">FROM</span> <span class="n">sightings</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="k">ALL</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="k">ALL</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌───────┬───────────────────────┬───────────┐
│ pond  │   first_three_rings   │ sightings │
├───────┼───────────────────────┼───────────┤
│ mill  │ [R0125, R0127, R0122] │ 96        │
│ north │ [R0096, R0160, R0180] │ 117       │
│ reed  │ [R0109, R0323, R0312] │ 80        │
│ south │ [R0215, R0315, R0076] │ 107       │
└───────┴───────────────────────┴───────────┘
</code></pre></div></div>

<h2 id="writing-columns-well">Writing Columns Well</h2>

<p>How you write data determines how fast later queries can read it. Write Parquet, partition on the columns people filter by, and sort so that similar values sit together.</p>

<p>This query writes the sightings to folders such as <code class="language-plaintext highlighter-rouge">lake/year=2026/pond=north/</code>, with compressed Parquet files in each:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">COPY</span> <span class="p">(</span><span class="k">SELECT</span> <span class="o">*</span><span class="p">,</span> <span class="nf">year</span><span class="p">(</span><span class="n">seen_at</span><span class="p">)</span> <span class="k">AS</span> <span class="n">year</span> <span class="k">FROM</span> <span class="n">sightings</span><span class="p">)</span>
<span class="k">TO</span> <span class="s1">'lake'</span>
<span class="p">(</span><span class="k">FORMAT</span> <span class="k">parquet</span><span class="p">,</span> <span class="k">PARTITION_BY</span> <span class="p">(</span><span class="n">year</span><span class="p">,</span> <span class="n">pond</span><span class="p">),</span> <span class="k">COMPRESSION</span> <span class="k">zstd</span><span class="p">);</span>
</code></pre></div></div>

<p><strong>Sort before you write.</strong> Compression works best on runs of identical values. Sorting by low-cardinality columns first makes those runs longer, and it makes the min and max statistics tighter, so more row groups can be skipped.</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">COPY</span> <span class="p">(</span><span class="k">SELECT</span> <span class="o">*</span> <span class="k">FROM</span> <span class="n">sightings</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">pond</span><span class="p">,</span> <span class="n">species</span><span class="p">,</span> <span class="n">seen_at</span><span class="p">)</span>
<span class="k">TO</span> <span class="s1">'sightings_sorted.parquet'</span> <span class="p">(</span><span class="k">FORMAT</span> <span class="k">parquet</span><span class="p">,</span> <span class="k">ROW_GROUP_SIZE</span> <span class="mi">122_880</span><span class="p">);</span>
</code></pre></div></div>

<p><strong>Pick narrow types.</strong> A smaller type takes less space. Use <code class="language-plaintext highlighter-rouge">ENUM</code> for small fixed sets, <code class="language-plaintext highlighter-rouge">DATE</code> instead of <code class="language-plaintext highlighter-rouge">TIMESTAMP</code> when you don’t need the time, and <code class="language-plaintext highlighter-rouge">SMALLINT</code> when values stay small. Here, <code class="language-plaintext highlighter-rouge">species</code> has only five possible values, so it becomes an <code class="language-plaintext highlighter-rouge">ENUM</code>:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">CREATE</span> <span class="k">TYPE</span> <span class="n">species_t</span> <span class="k">AS</span> <span class="nb">ENUM</span> <span class="p">(</span><span class="s1">'mallard'</span><span class="p">,</span> <span class="s1">'teal'</span><span class="p">,</span> <span class="s1">'wigeon'</span><span class="p">,</span> <span class="s1">'pintail'</span><span class="p">,</span> <span class="s1">'tufted'</span><span class="p">);</span>
<span class="k">ALTER</span> <span class="k">TABLE</span> <span class="n">sightings</span> <span class="k">ALTER</span> <span class="n">species</span> <span class="k">TYPE</span> <span class="n">species_t</span><span class="p">;</span>
</code></pre></div></div>

<p><strong>Check the plan rather than guessing.</strong> <code class="language-plaintext highlighter-rouge">EXPLAIN ANALYZE</code> shows which columns were read, which filters were pushed into the scan, and where the time went:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">EXPLAIN</span> <span class="k">ANALYZE</span>
<span class="k">SELECT</span> <span class="n">species</span><span class="p">,</span> <span class="nf">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">FROM</span> <span class="s1">'lake/**/*.parquet'</span> <span class="k">WHERE</span> <span class="n">pond</span> <span class="o">=</span> <span class="s1">'north'</span> <span class="k">GROUP</span> <span class="k">BY</span> <span class="k">ALL</span><span class="p">;</span>
</code></pre></div></div>

<p>The part of the output that matters here is the table scan. DuckDB scans 2 of the 8 files, because <code class="language-plaintext highlighter-rouge">pond</code> is a partition column, and it reads only the <code class="language-plaintext highlighter-rouge">species</code> column:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Table Scan
  Function: PARQUET_SCAN
  Projections: species
  File Filters: pond = 'north'
  Scanning Files: 2/8
  Total Files Read: 2
</code></pre></div></div>

<blockquote>
  <p>Tip <strong>Name your columns, and avoid <code class="language-plaintext highlighter-rouge">SELECT *</code> in production.</strong> Every column you leave out is one DuckDB never decompresses. On a 60-column table, selecting 4 columns can cut the data read dramatically.</p>
</blockquote>

<p><strong>Query DataFrames in place.</strong> DuckDB queries pandas and Polars DataFrames and Arrow tables directly, and it returns results in the same formats. Converting a result to Polars goes through Arrow, so install <code class="language-plaintext highlighter-rouge">pyarrow</code> as well.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">duckdb</span>
<span class="kn">import</span> <span class="nn">polars</span> <span class="k">as</span> <span class="n">pl</span>

<span class="n">sightings</span> <span class="o">=</span> <span class="n">pl</span><span class="p">.</span><span class="n">read_parquet</span><span class="p">(</span><span class="s">"sightings/2026.parquet"</span><span class="p">)</span>
<span class="n">duckdb</span><span class="p">.</span><span class="n">sql</span><span class="p">(</span><span class="s">"SELECT pond, count(*) AS sightings FROM sightings GROUP BY ALL ORDER BY ALL"</span><span class="p">).</span><span class="n">pl</span><span class="p">()</span>
</code></pre></div></div>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>shape: (4, 2)
┌───────┬───────────┐
│ pond  ┆ sightings │
│ ---   ┆ ---       │
│ str   ┆ i64       │
╞═══════╪═══════════╡
│ mill  ┆ 54        │
│ north ┆ 58        │
│ reed  ┆ 48        │
│ south ┆ 56        │
└───────┴───────────┘
</code></pre></div></div>

<h2 id="conclusion">Conclusion</h2>

<p>Each feature in this post follows one rule: read only the columns and values your query needs. This table summarizes the tricks:</p>

<table>
  <thead>
    <tr>
      <th>Trick</th>
      <th>What it saves you</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">FROM 'file.parquet'</code></td>
      <td>Loading data before querying it</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">SELECT * EXCLUDE (...)</code></td>
      <td>Listing 40 columns to drop 2</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">COLUMNS('regex')</code></td>
      <td>Repeating one expression per column</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">SUMMARIZE</code></td>
      <td>Writing a profiling query by hand</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">GROUP BY ALL</code></td>
      <td>Keeping <code class="language-plaintext highlighter-rouge">SELECT</code> and <code class="language-plaintext highlighter-rouge">GROUP BY</code> in sync</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">count(*) FILTER (WHERE ...)</code></td>
      <td>One query per category</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">PIVOT</code> / <code class="language-plaintext highlighter-rouge">UNPIVOT</code></td>
      <td>Walls of <code class="language-plaintext highlighter-rouge">CASE</code> expressions</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">QUALIFY</code></td>
      <td>Subqueries around window functions</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ASOF JOIN</code></td>
      <td>Fuzzy time-matching logic</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">COPY ... PARTITION_BY</code></td>
      <td>Hand-built folder layouts</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ORDER BY</code> before <code class="language-plaintext highlighter-rouge">COPY</code></td>
      <td>Poor compression and unskippable row groups</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">EXPLAIN ANALYZE</code></td>
      <td>Guessing where the time went</td>
    </tr>
  </tbody>
</table>

<p>Row stores, such as transactional database systems, keep each record together. That suits lookups of one whole record. Analytical queries usually need the opposite: a few columns across many records. Keep your ducks in a column, and your queries will keep up.</p>]]></content>
      

      
        <author>
          <name>The DuckDB team</name>
        </author>
      

      
        
      

      
        <category term="using-duckdb" />
      

      
      
        <summary type="html"><![CDATA[DuckDB is fast among other reasons because it stores data by column, so a query reads only the columns it names. This post covers DuckDB features that take advantage of that design choice: querying files in place, column-level SQL, aggregation shortcuts, window functions, ASOF joins, and writing well-organized Parquet.]]></summary>
      

      
      
        
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://duckdb.org/images/blog/thumbs/ducks-column.png" />
        <media:content medium="image" url="https://duckdb.org/images/blog/thumbs/ducks-column.png" xmlns:media="http://search.yahoo.com/mrss/" />
      
    </entry>
  
    <entry>
      

      <title type="html">How JetBrains Built Cross-Database Queries into DataGrip with DuckDB</title>
      <link href="https://duckdb.org/2026/11/05/jetbrains-datagrip.html" rel="alternate" type="text/html" title="How JetBrains Built Cross-Database Queries into DataGrip with DuckDB" />
      <published>2026-11-05T00:00:00+00:00</published>
      <updated>2026-11-05T00:00:00+00:00</updated>
      <id>https://duckdb.org/2026/11/05/jetbrains-datagrip</id>
      
      
        <content type="html" xml:base="https://duckdb.org/2026/11/05/jetbrains-datagrip.html"><![CDATA[<p>When <a href="https://www.jetbrains.com/">JetBrains</a> set out to let developers <a href="https://www.jetbrains.com/datagrip/whatsnew/#connectivity">join data across different database connections in a single query</a>, it chose not to build its own cross-database query engine. Instead, <a href="https://www.jetbrains.com/datagrip/">DataGrip</a>, its database IDE, embeds DuckDB to execute those queries, and exposes DuckDB’s SQL dialect directly to the developers writing them.</p>

<figure class="quote"><blockquote class="quote-large">
  <p>Quote</p>

  <p>DuckDB turned out to be the simplest option to integrate.</p>

  
</blockquote><figcaption class="quote-author">Ilia Epelbaum, DataGrip, JetBrains</figcaption></figure>

<h2 id="querying-across-data-sources">Querying across Data Sources</h2>

<p>DataGrip is JetBrains’ IDE for working with databases and writing SQL, developed since 2015. The same database functionality is also available as a plugin inside the other JetBrains IDEs, so the feature reaches well beyond DataGrip itself.</p>

<p>For a long time, users had been asking for one thing in particular: the ability to run a single query across more than one data source. The most common request was to join data from different database connections in one query. DataGrip could already execute queries against each connection, but nothing tied the results together, so the team needed an engine that could.</p>

<h2 id="choosing-duckdb-over-building-its-own">Choosing DuckDB over Building Its Own</h2>

<p>JetBrains explored several approaches. It considered <a href="https://calcite.apache.org/">Apache Calcite</a>, handling the queries itself using <a href="https://plugins.jetbrains.com/docs/intellij/psi.html">PSI</a> (Program Structure Interface, the internal code representation JetBrains uses across its IDEs), and DuckDB.</p>

<p>DuckDB won on ease of integration. <strong>“DuckDB turned out to be the simplest option to integrate,”</strong> says Ilia Epelbaum, who works on the DataGrip team. The deciding feature was the ability to register a custom table function: it gave JetBrains a straightforward way to connect DuckDB to the query-execution functionality DataGrip already had. DuckDB was also preferred over lighter alternatives such as <a href="https://h2database.com/html/main.html">H2</a> because it brought more capabilities, including query optimizations like projection pushdown.</p>

<p>Maxim Sobolevskiy, Head of Database Ecosystem at JetBrains, puts the result in concrete terms. <strong>“With DuckDB and its support for custom table functions, cross-database queries have finally become practical in DataGrip,”</strong> he says. <strong>“Users can join data from PostgreSQL, MySQL, MongoDB, or any other supported database in one query, without setting up extra infrastructure.”</strong> The embedded alternatives the team evaluated could not do this, because <strong>“extending them required either native code or a complicated implementation.”</strong></p>

<p>Epelbaum came to the project knowing the territory. He had been a database developer working on <a href="https://trino.io/">Trino</a> before moving into database tooling, and already knew how flexible DuckDB was. That background is part of why the team reached for it rather than writing and maintaining a cross-database query engine of its own.</p>

<h2 id="duckdb-in-plain-sight">DuckDB in Plain Sight</h2>

<p>Developers know DuckDB is there. Because a cross-source join runs through a DuckDB table function, the query itself is written in DuckDB’s SQL dialect, and DataGrip tells developers so. <strong>“We highlight that it’s DuckDB,”</strong> Epelbaum says, so that someone writing a join across connections knows they are writing a DuckDB query.</p>

<p>JetBrains has gone further and supports DuckDB as a first-class dialect in its own right, not only as the engine behind cross-source joins. Epelbaum contributed syntax highlighting for DuckDB, including the syntax introduced in <a href="/2026/10/21/announcing-duckdb-200.html">DuckDB 2.0</a>.</p>

<h2 id="an-initial-solution-still-evolving">An Initial Solution, Still Evolving</h2>

<p>This is still a first version. <strong>“We’ve built the initial solution, and we want to see how users actually use it in practice,”</strong> Epelbaum says. Only after that does the team plan to layer on more of DuckDB’s optimizations.</p>

<p>Two directions are on the roadmap. The first is to take fuller advantage of DuckDB’s query optimizations. The second is to use DuckDB for file-based data sources, reading files the way it already reads across connections. Epelbaum also singled out DuckDB’s <a href="/docs/2.0/sql/dialect/friendly_sql.html">friendly SQL</a> as something the team values in day-to-day use.</p>

<p>For now, DuckDB sits at the core of a feature that JetBrains users had wanted for years, letting them join across their databases without JetBrains having to become a query-engine vendor to make it happen.</p>

<h2 id="about-jetbrains-and-datagrip">About JetBrains and DataGrip</h2>

<p>JetBrains builds professional developer tools, including IntelliJ IDEA, PyCharm, and the Kotlin language, that have served millions of programmers for more than 20 years. <a href="https://www.jetbrains.com/datagrip/">DataGrip</a>, its database IDE, helps developers and data engineers query, explore, and manage multiple databases from a single environment.</p>]]></content>
      

      
        <author>
          <name>Ilia Epelbaum</name>
        </author>
      
        <author>
          <name>Geertjan Wielenga</name>
        </author>
      
        <author>
          <name>Tim Cox</name>
        </author>
      

      
        
      

      
        <category term="case-study" />
      

      
      
        <summary type="html"><![CDATA[JetBrains users had long asked to join data across different database connections in a single query. Rather than build its own cross-database query engine, JetBrains embedded DuckDB in DataGrip, using DuckDB’s custom table functions to connect it to the IDE’s existing query execution. This is why DuckDB won out over the alternatives, and where the integration goes next.]]></summary>
      

      
      
        
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://duckdb.org/images/blog/thumbs/datagrip.png" />
        <media:content medium="image" url="https://duckdb.org/images/blog/thumbs/datagrip.png" xmlns:media="http://search.yahoo.com/mrss/" />
      
    </entry>
  
    <entry>
      

      <title type="html">Bringing Local Analytics to the Quant&apos;s Desktop</title>
      <link href="https://duckdb.org/2026/11/03/bringing-local-analytics-to-the-quants-desktop.html" rel="alternate" type="text/html" title="Bringing Local Analytics to the Quant&apos;s Desktop" />
      <published>2026-11-03T00:00:00+00:00</published>
      <updated>2026-11-03T00:00:00+00:00</updated>
      <id>https://duckdb.org/2026/11/03/bringing-local-analytics-to-the-quants-desktop</id>
      
      
        <content type="html" xml:base="https://duckdb.org/2026/11/03/bringing-local-analytics-to-the-quants-desktop.html"><![CDATA[<figure class="quote"><blockquote class="quote-large">
  <p>Quote</p>

  <p>I like the simplicity of just a small thing running and working. And then you can get more complex.</p>

  
</blockquote><figcaption class="quote-author"><img src="/images/blog/authors/ryan_hamilton.jpg" alt="" class="avatar" loading="lazy">Ryan Hamilton, founder, <a href="https://www.timestored.com/">TimeStored</a></figcaption></figure>

<h2 id="fifteen-years-of-heavyweight-infrastructure">Fifteen Years of Heavyweight Infrastructure</h2>

<p>For about fifteen years, <a href="https://www.linkedin.com/in/ryananthonyhamilton/">Ryan Hamilton</a> has built large market-data platforms for banks and hedge funds. Most of that work was in <a href="https://kx.com/">kdb+</a>, integrated with real-time messaging systems such as <a href="https://solace.com/">Solace</a>. He built much of the platform at UBS and almost all of it at Citi, contributed to Morgan Stanley's, and most recently worked at a hedge fund.</p>

<p>His users are typically teams of 10 to 15 quants. They are deep specialists in finance who spend anywhere from a tenth to more than half their time on technology. Ryan's job has been to store their data efficiently so they can get on with their work. Sometimes he leads a team to do that. Sometimes he builds it himself. Sometimes he talks quants out of building infrastructure on their own.</p>

<h2 id="problems-that-didnt-need-a-heavyweight-answer">Problems That Didn't Need a Heavyweight Answer</h2>

<p>Alongside that work, startups, smaller tech firms, and smaller funds kept asking Ryan the same question: what should we run this on?</p>

<p>For years he had no good answer. He tried other systems but found that their license was prohibitively expensive, their setup didn't offer an embedded mode of operation, or they were much more operationally involved than he wanted at the time. For some clients, the honest answer was that he would write something in C for their narrow use case.</p>

<h2 id="a-different-starting-point">A Different Starting Point</h2>

<p>DuckDB was different. It was small, embedded, reliable, and analytically capable, and a team could start with it inside an application without standing up a server.</p>

<p><strong>“I like the simplicity of just a small thing running and working,”</strong> Ryan says. <strong>“And then you can get more complex.”</strong></p>

<p>That let him give smaller firms a straight recommendation. DuckDB might not scale to everything, but it would run well and serve them for a long time. For roughly 90% of use cases, he reasoned, it would carry a team for years. By the time they outgrew it, they would understand their workload well enough to choose what came next. In many cases, DuckDB has expanded quickly enough that they never needed to move.</p>

<h2 id="qstudio-a-local-analytical-sandbox">QStudio: A Local Analytical Sandbox</h2>

<p>The clearest illustration is <a href="https://www.timestored.com/qstudio/">QStudio</a>, the analytics IDE Ryan released about 13 years ago. It was originally built for kdb+ and now connects to around 15 databases. He leaves database administration to tools like <a href="https://dbeaver.io/">DBeaver</a> and focuses QStudio on analytics and charting.</p>

<p>DuckDB was the first deep integration, and it changed how quants work with expensive queries. The workflow runs like this. An analyst runs a heavy query against a remote database. Some of these take up to 20 minutes. QStudio then saves the result locally as Parquet through DuckDB, with a click in the UI.</p>

<p>The next day, the analyst queries that saved result directly, without rerunning the original workload:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span>
    <span class="n">symbol</span><span class="p">,</span>
    <span class="nf">avg</span><span class="p">(</span><span class="n">price</span><span class="p">)</span> <span class="k">AS</span> <span class="n">avg_price</span><span class="p">,</span>
    <span class="nf">sum</span><span class="p">(</span><span class="n">volume</span><span class="p">)</span> <span class="k">AS</span> <span class="n">total_volume</span>
<span class="k">FROM</span> <span class="s1">'results/trades_2026-11-10.parquet'</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="k">ALL</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">total_volume</span> <span class="k">DESC</span><span class="p">;</span>
</code></pre></div></div>

<p>The result is a personal sandbox where quants can build on their own earlier work. It proved popular, and Ryan found its performance close to kdb+'s.</p>

<p>Because QStudio is a Java Swing desktop application deployed inside banks, the integration depends on DuckDB's <a href="/docs/2.0/clients/java/overview.html">Java client</a>. Ryan's early version relied on inefficient workarounds to get appending working. Once a dedicated Java developer joined and rebuilt the <a href="/docs/2.0/clients/java/data_import.html">Appender</a> properly, every kink was ironed out.</p>

<p><strong>“It just worked,”</strong> Ryan says, <strong>“which is the highest praise I would give any engineering thing.”</strong></p>

<p>That experience became the basis of his DuckCon talk. His argument was that an open-source engine already beat a far more exotic and expensive stack in some areas. DuckDB has moved well ahead since then.</p>

<h2 id="pulse-duckdb-by-default">Pulse: DuckDB by Default</h2>

<p>QStudio was never a significant direct revenue generator, but it got a very small company onto the approved-vendor lists of some very large firms, which is hard for small vendors to do. When Ryan's company, TimeStored, launched <a href="https://www.timestored.com/pulse/">Pulse</a>, a real-time HTML visualization tool that is now its main product, that path into large firms already existed.</p>

<p>Ryan reached for DuckDB again. Pulse uses it to snapshot and cache data. What began as an integration experiment had become a repeated TimeStored architecture pattern. DuckDB sits in the embedded storage and query layer, and increasingly supports AI-assisted data exploration. Excel exports and similar user-facing features stay in the application's UI. That is partly to keep styling intact, and partly because bank users often can't install extensions at all.</p>

<h2 id="peachq-back-to-q">PeachQ: Back to Q</h2>

<p>Ryan's newest project is <a href="https://peachq.org/">PeachQ</a>, an open-source implementation of the <a href="https://en.wikipedia.org/wiki/Q_(programming_language_from_Kx_Systems)">Q language</a>. Ryan loves Q as a language but thinks DuckDB is ahead as a database, so PeachQ separates the two.</p>

<p>PeachQ uses the Rayforce in-memory engine and DuckDB-backed historical storage to deliver a modern, open-source alternative to kdb+, bringing together real-time processing, powerful analytics, and efficient storage in a single system. Ryan's recent work on C extensions points the same way, along with experiments with newer formats such as <a href="/docs/2.0/core_extensions/vortex.html">Vortex</a> and custom table formats. He credits DuckDB's <a href="/docs/2.0/extensions/overview.html">extension</a> API with letting people add features cleanly, unlike the fragile workarounds he and others once built into closed systems. Often, he notes, DuckDB later builds those features itself.</p>

<h2 id="learn-more">Learn More</h2>

<p>Ryan's DuckCon talk gives a short tour of this work.</p>

<div class="video-container">
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/viMXP_TG6tU" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen=""></iframe>
</div>

<p>You can explore QStudio, now open source, and try PeachQ at <a href="https://peachq.org/">peachq.org</a>.</p>

<p>We would like to thank Ryan for the conversation. You can follow his work on DuckDB, Q, and TimeStored at <a href="https://www.timestored.com/">timestored.com</a>. And if you are reading this, are using DuckDB, and would like to share your story, drop us a line at <a href="mailto:geertjan@ducklabs.com">geertjan@ducklabs.com</a>.</p>]]></content>
      

      
        <author>
          <name>Ryan Hamilton</name>
        </author>
      
        <author>
          <name>Geertjan Wielenga</name>
        </author>
      
        <author>
          <name>Tim Cox</name>
        </author>
      

      
        
      

      
        <category term="case-study" />
      

      
      
        <summary type="html"><![CDATA[After years building kdb+-based data platforms for banks and hedge funds, Ryan Hamilton wanted an analytical engine he could recommend to smaller teams without specialized infrastructure or expensive licensing. DuckDB gave him a small, embedded way to bring fast local analytics into QStudio and Pulse, and it is now shaping his next open-source project, PeachQ.]]></summary>
      

      
      
        
        <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://duckdb.org/images/blog/thumbs/quants-desktop.png" />
        <media:content medium="image" url="https://duckdb.org/images/blog/thumbs/quants-desktop.png" xmlns:media="http://search.yahoo.com/mrss/" />
      
    </entry>
  
</feed>
