<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Direct Dataset</title>
    <description>The latest articles on DEV Community by Direct Dataset (@directdataset).</description>
    <link>https://dev.to/directdataset</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4284544%2Feec52e27-f6bf-433c-968a-a74e28bd84db.png</url>
      <title>DEV Community: Direct Dataset</title>
      <link>https://dev.to/directdataset</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/directdataset"/>
    <language>en</language>
    <item>
      <title>Keeping the history of a page that changes every day: an event log for listing prices, queried in DuckDB</title>
      <dc:creator>Direct Dataset</dc:creator>
      <pubDate>Sat, 05 Dec 2026 11:01:03 +0000</pubDate>
      <link>https://dev.to/directdataset/keeping-the-history-of-a-page-that-changes-every-day-an-event-log-for-listing-prices-queried-in-1fej</link>
      <guid>https://dev.to/directdataset/keeping-the-history-of-a-page-that-changes-every-day-an-event-log-for-listing-prices-queried-in-1fej</guid>
      <description>&lt;p&gt;A property listing is a record that keeps changing under you. The asking price moves, the advert gets upgraded, the agent changes, it disappears for a week and comes back. The page only ever shows the current state. If you want to answer "what was the asking price on 1 September?" or "how long do listings stay up?", you have to keep the history yourself.&lt;/p&gt;

&lt;p&gt;This post walks through the model we use at &lt;a href="https://directdataset.com" rel="noopener noreferrer"&gt;Direct Dataset&lt;/a&gt; for UAE property listings, recorded daily from June 2026, and six DuckDB queries that get the history back out. Every query below was run on a free dataset of 500 listings, and the output shown is the real output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two ways to keep history
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Daily snapshots.&lt;/strong&gt; Save the full table every day. Simple to write and simple to query for one day, but almost every row is a copy of yesterday's. A listing that sits unchanged for 60 days is stored 60 times, and to find out when the price changed you have to diff consecutive days.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An event log.&lt;/strong&gt; Keep one table with the latest state of each listing, and a second table with one row per listing per day &lt;em&gt;something changed&lt;/em&gt;. A listing that never changes has a single event. This is the slowly changing dimension idea, stored as events instead of validity ranges.&lt;/p&gt;

&lt;p&gt;We use the event log. Two tables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;bayut_listings&lt;/code&gt;: one row per listing, with its latest values, plus &lt;code&gt;firstSeenDate&lt;/code&gt;, &lt;code&gt;lastSeenDate&lt;/code&gt; and &lt;code&gt;delistedOn&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bayut_listing_events&lt;/code&gt;: one row per listing per day something changed, with &lt;code&gt;changeType&lt;/code&gt;, &lt;code&gt;changedFields&lt;/code&gt;, &lt;code&gt;prevPrice&lt;/code&gt; and &lt;code&gt;price&lt;/code&gt;, and the listing's other values as they were that day.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;changeType&lt;/code&gt; takes four values:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;changeType&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;first_seen&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The first day the listing was recorded&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;changed&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;One or more fields differ from the day before; &lt;code&gt;changedFields&lt;/code&gt; names them, pipe-separated&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;delisted&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The listing is gone from the source&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;relisted&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;It came back after being delisted&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three design choices make it usable:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Store the old value and the new value in the same row.&lt;/strong&gt; &lt;code&gt;prevPrice&lt;/code&gt; and &lt;code&gt;price&lt;/code&gt; sit side by side, so a price change can be read without a self-join or a window function.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Name what changed.&lt;/strong&gt; &lt;code&gt;changedFields&lt;/code&gt; lets you separate a price cut from an advert being renewed or a verification badge appearing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't infer anything from a bad day.&lt;/strong&gt; A listing is only marked &lt;code&gt;delisted&lt;/code&gt; after it has been missing from several complete daily captures. If a day's collection is incomplete, nothing is concluded from what is missing. Without that rule, one failed run would look like a wave of delistings followed by a wave of relistings.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Get the data
&lt;/h2&gt;

&lt;p&gt;The free dataset is on the &lt;a href="https://directdataset.com/datasets/uae-property-listings-price-history#samples" rel="noopener noreferrer"&gt;UAE property listings and price history page&lt;/a&gt;: enter an email address and the download link appears straight away. It has 500 Bayut listings and 500 Property Finder listings with their events, as Parquet and CSV. This post uses the two Bayut tables.&lt;/p&gt;

&lt;p&gt;Install &lt;a href="https://duckdb.org" rel="noopener noreferrer"&gt;DuckDB&lt;/a&gt;, open a terminal in the folder that holds the files and run &lt;code&gt;duckdb&lt;/code&gt;. DuckDB reads Parquet files in place, so there is nothing to import.&lt;/p&gt;

&lt;p&gt;Two things to keep in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;500 listings show how the record works. They are not a market sample, so none of the numbers below are market figures.&lt;/li&gt;
&lt;li&gt;Dates are ISO strings (&lt;code&gt;2026-09-14&lt;/code&gt;), so they sort and compare correctly as text and cast cleanly with &lt;code&gt;CAST(date AS DATE)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. What kinds of events are there?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;changeType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="cm"&gt;(*) AS events
FROM 'bayut_listing_events.parquet'
GROUP BY changeType
ORDER BY events DESC;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌────────────┬────────┐
│ changeType │ events │
├────────────┼────────┤
│ changed    │ 660    │
│ first_seen │ 500    │
│ delisted   │ 431    │
│ relisted   │ 69     │
└────────────┴────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1,660 events for 500 listings, recorded from 21 June to 25 November 2026. Daily snapshots of the same listings, one row per listing per day it was live, would have taken 19,249 rows. Every listing has exactly one &lt;code&gt;first_seen&lt;/code&gt;. 69 relistings came from 60 listings, so a few came back more than once.&lt;/p&gt;

&lt;p&gt;Most &lt;code&gt;changed&lt;/code&gt; events are not price changes. Grouping by &lt;code&gt;changedFields&lt;/code&gt; shows advert upgrades, amenities edits and verification changes ahead of price. That is why the column exists.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. One listing's full story
&lt;/h2&gt;

&lt;p&gt;Pick the listing with the most price changes and replay it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;busiest&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;externalID&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="s1"&gt;'bayut_listing_events.parquet'&lt;/span&gt;
  &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;changeType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'changed'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;prevPrice&lt;/span&gt;
  &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;externalID&lt;/span&gt;
  &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="cm"&gt;(*) DESC, externalID
  LIMIT 1
)
SELECT date, changeType, prevPrice, price
FROM 'bayut_listing_events.parquet'
WHERE externalID IN (SELECT externalID FROM busiest)
  AND (changeType &amp;lt;&amp;gt; 'changed' OR price &amp;lt;&amp;gt; prevPrice)
ORDER BY date;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌────────────┬────────────┬───────────┬─────────┐
│    date    │ changeType │ prevPrice │  price  │
├────────────┼────────────┼───────────┼─────────┤
│ 2026-09-14 │ first_seen │ NULL      │ 37999.0 │
│ 2026-09-16 │ changed    │ 37999.0   │ 37994.0 │
│ 2026-09-18 │ changed    │ 37994.0   │ 37996.0 │
│ 2026-09-19 │ changed    │ 37996.0   │ 37994.0 │
│ 2026-09-25 │ changed    │ 37994.0   │ 37977.0 │
│ 2026-09-26 │ changed    │ 37977.0   │ 37976.0 │
│ 2026-09-30 │ changed    │ 37976.0   │ 36999.0 │
│ 2026-10-03 │ changed    │ 36999.0   │ 36996.0 │
│ 2026-10-04 │ changed    │ 36996.0   │ 36997.0 │
│ 2026-10-07 │ changed    │ 36997.0   │ 36996.0 │
│ 2026-10-14 │ delisted   │ 36996.0   │ 36996.0 │
└────────────┴────────────┴───────────┴─────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A two-bedroom flat for rent in Ajman, at AED 37,999 a year. Nine price changes in three weeks, and only one of them, on 30 September, is a real cut (about 2.6%). The rest are moves of one to seventeen dirhams. Then it was taken down on 14 October.&lt;/p&gt;

&lt;p&gt;A snapshot taken on any single day would show one of these numbers and nothing else.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Separate real price moves from noise
&lt;/h2&gt;

&lt;p&gt;Because the old and new price are in one row, filtering by size is one expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="cm"&gt;(*) AS price_moves,
       count(*)&lt;/span&gt; &lt;span class="k"&gt;FILTER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;prevPrice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;cuts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="cm"&gt;(*) FILTER (WHERE price &amp;gt; prevPrice) AS rises,
       count(*)&lt;/span&gt; &lt;span class="k"&gt;FILTER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;prevPrice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;prevPrice&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.01&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;moves_1pct_plus&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="s1"&gt;'bayut_listing_events.parquet'&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;changeType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'changed'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;prevPrice&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────┬──────┬───────┬─────────────────┐
│ price_moves │ cuts │ rises │ moves_1pct_plus │
├─────────────┼──────┼───────┼─────────────────┤
│ 79          │ 59   │ 20    │ 68              │
└─────────────┴──────┴───────┴─────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;11 of the 79 moves were under 1%. We keep them anyway. If small moves were dropped at collection time you could never study them; kept, they cost one &lt;code&gt;WHERE&lt;/code&gt; clause to ignore.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Rebuild the market on a past date
&lt;/h2&gt;

&lt;p&gt;This is the main reason for the model. The state of a listing on day D is its latest event on or before D. If that event is &lt;code&gt;delisted&lt;/code&gt;, it was not live.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nb"&gt;CAST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="kt"&gt;DATE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nf"&gt;generate_series&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;DATE&lt;/span&gt; &lt;span class="s1"&gt;'2026-07-01'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;DATE&lt;/span&gt; &lt;span class="s1"&gt;'2026-11-01'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;INTERVAL&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="no"&gt;MONTH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="nf"&gt;t&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;latest&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;externalID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;changeType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="nb"&gt;row_number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;externalID&lt;/span&gt; &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;date&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;rn&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt;
  &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="s1"&gt;'bayut_listing_events.parquet'&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="nb"&gt;CAST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;date&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="kt"&gt;DATE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="cm"&gt;(*) AS live_listings
FROM latest
WHERE rn = 1 AND changeType &amp;lt;&amp;gt; 'delisted'
GROUP BY day
ORDER BY day;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌────────────┬───────────────┐
│    day     │ live_listings │
├────────────┼───────────────┤
│ 2026-07-01 │ 142           │
│ 2026-08-01 │ 160           │
│ 2026-09-01 │ 108           │
│ 2026-10-01 │ 128           │
│ 2026-11-01 │ 138           │
└────────────┴───────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add &lt;code&gt;e.price&lt;/code&gt; to the &lt;code&gt;latest&lt;/code&gt; CTE and you have every live listing's asking price on each of those days, ready for a median by area or bedroom count. Every event row carries the listing's values as they were that day, so no second lookup is needed.&lt;/p&gt;

&lt;p&gt;The join is a range join (&lt;code&gt;&amp;lt;=&lt;/code&gt;), which grows with days × events. On the full dataset, restrict it to the listings you need first, or use DuckDB's &lt;code&gt;ASOF JOIN&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. How long do listings stay up?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;purpose&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="cm"&gt;(*) AS taken_down,
       median(date_diff('day', CAST(firstSeenDate AS DATE), CAST(delistedOn AS DATE))) AS median_days_live
FROM 'bayut_listings.parquet'
WHERE delistedOn IS NOT NULL AND delistedOn &amp;lt;&amp;gt; ''
GROUP BY purpose
ORDER BY purpose;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌──────────┬────────────┬──────────────────┐
│ purpose  │ taken_down │ median_days_live │
├──────────┼────────────┼──────────────────┤
│ for-rent │ 190        │ 32.0             │
│ for-sale │ 172        │ 33.0             │
└──────────┴────────────┴──────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two caveats that apply to any history you start recording partway through:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Left-censoring.&lt;/strong&gt; &lt;code&gt;firstSeenDate&lt;/code&gt; is the first day &lt;em&gt;we&lt;/em&gt; recorded the listing. Anything already live on 21 June looks younger than it is.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Right-censoring.&lt;/strong&gt; Listings still live are left out, and they are the long-lived ones. A proper answer uses survival methods; the median here is a first look.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;delistedOn&lt;/code&gt; is set only on listings whose latest event is &lt;code&gt;delisted&lt;/code&gt;; a listing that came back has it cleared. So this counts each listing's current state, not every delisting event.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Join the two tables
&lt;/h2&gt;

&lt;p&gt;The latest-state table gives you attributes; the events table gives you behaviour. Which listings had at least one price cut, by purpose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;purpose&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;DISTINCT&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;externalID&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;listings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;DISTINCT&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;externalID&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;with_a_cut&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="s1"&gt;'bayut_listings.parquet'&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="s1"&gt;'bayut_listing_events.parquet'&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
  &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;externalID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;externalID&lt;/span&gt;
 &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;changeType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'changed'&lt;/span&gt;
 &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prevPrice&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;purpose&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;purpose&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌──────────┬──────────┬────────────┐
│ purpose  │ listings │ with_a_cut │
├──────────┼──────────┼────────────┤
│ for-rent │ 260      │ 25         │
│ for-sale │ 240      │ 9          │
└──────────┴──────────┴────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The filter on the event type sits in the &lt;code&gt;ON&lt;/code&gt; clause, not in &lt;code&gt;WHERE&lt;/code&gt;, so listings without a cut stay in the count. Put it in &lt;code&gt;WHERE&lt;/code&gt; and the &lt;code&gt;LEFT JOIN&lt;/code&gt; quietly turns into an inner join.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we'd do the same way again
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Latest state plus events, not snapshots.&lt;/strong&gt; Small, fast, and any past day can still be rebuilt.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Old and new value in one row.&lt;/strong&gt; Most questions become a filter instead of a window function.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A named list of changed fields.&lt;/strong&gt; It separates price behaviour from advert housekeeping.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Only conclude "gone" from complete days.&lt;/strong&gt; The most important rule in the collector, and the one you can't add afterwards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stable identifiers.&lt;/strong&gt; &lt;code&gt;externalID&lt;/code&gt; joins the two tables today and joins next month's update to this month's file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The full dataset
&lt;/h2&gt;

&lt;p&gt;The full UAE property listings dataset holds more than 3.8 million listing records from Bayut and Property Finder, across every emirate, recorded daily since June 2026, in the same tables and columns as the free one. It comes as Parquet, CSV or SQLite with a data dictionary. Details are on the &lt;a href="https://directdataset.com/datasets/uae-property-listings-price-history" rel="noopener noreferrer"&gt;dataset page&lt;/a&gt;, and the &lt;a href="https://directdataset.com/docs" rel="noopener noreferrer"&gt;docs&lt;/a&gt; cover loading the files and adding updates.&lt;/p&gt;

&lt;p&gt;Direct Dataset has &lt;a href="https://directdataset.com/free-datasets" rel="noopener noreferrer"&gt;free datasets&lt;/a&gt; for each of its 35 datasets, from Dubai property sales to retail prices and product reviews. Questions about the model or the data: &lt;a href="mailto:hello@directdataset.com"&gt;hello@directdataset.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>duckdb</category>
      <category>dataengineering</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
