<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic select table_changes() return unexpected results in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/select-table-changes-return-unexpected-results/m-p/162268#M55054</link>
    <description>&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;My understanding is&lt;/P&gt;&lt;P&gt;SELECT *&lt;BR /&gt;FROM table_changes('mytable', x)&lt;/P&gt;&lt;P&gt;should return all changes from version x through the latest available version, regardless of when I run it. However what happen to me is:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;When immediately after a streaming table update it only returns changes for version x, this is as expected.&lt;/LI&gt;&lt;LI&gt;but after some times, it returns all versions 1, 2, ..., x-1, x, x+1, ..., this is not as expected. It should only return versions x, x+1, ....&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;in my example below, I expect the second query only return one row: 2026-04-08 8676 from version 25 only, but it return other versions as well. Any thoughts why?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hdu_0-1783525115352.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/28766i7347878FF9FCC0AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hdu_0-1783525115352.png" alt="hdu_0-1783525115352.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jul 2026 15:39:25 GMT</pubDate>
    <dc:creator>hdu</dc:creator>
    <dc:date>2026-07-08T15:39:25Z</dc:date>
    <item>
      <title>select table_changes() return unexpected results</title>
      <link>https://community.databricks.com/t5/data-engineering/select-table-changes-return-unexpected-results/m-p/162268#M55054</link>
      <description>&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;My understanding is&lt;/P&gt;&lt;P&gt;SELECT *&lt;BR /&gt;FROM table_changes('mytable', x)&lt;/P&gt;&lt;P&gt;should return all changes from version x through the latest available version, regardless of when I run it. However what happen to me is:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;When immediately after a streaming table update it only returns changes for version x, this is as expected.&lt;/LI&gt;&lt;LI&gt;but after some times, it returns all versions 1, 2, ..., x-1, x, x+1, ..., this is not as expected. It should only return versions x, x+1, ....&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;in my example below, I expect the second query only return one row: 2026-04-08 8676 from version 25 only, but it return other versions as well. Any thoughts why?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hdu_0-1783525115352.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/28766i7347878FF9FCC0AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hdu_0-1783525115352.png" alt="hdu_0-1783525115352.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2026 15:39:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/select-table-changes-return-unexpected-results/m-p/162268#M55054</guid>
      <dc:creator>hdu</dc:creator>
      <dc:date>2026-07-08T15:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: select table_changes() return unexpected results</title>
      <link>https://community.databricks.com/t5/data-engineering/select-table-changes-return-unexpected-results/m-p/162284#M55059</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/117946"&gt;@hdu&lt;/a&gt;,&lt;/P&gt;
&lt;P data-pm-slice="1 1 []"&gt;When you call table_changes('mytable', 25), the start argument is inclusive, and if you omit end, Databricks should return changes from version 25 through the latest available version only.&lt;/P&gt;
&lt;P&gt;So if you are literally seeing rows whose CDF metadata shows _commit_version &amp;lt; 25, that would not match the documented behaviour.&lt;/P&gt;
&lt;P&gt;That said, one important nuance is that table_changes returns row-level change events, not "new business dates." The rows include CDF metadata columns such as _commit_version, _commit_timestamp, and _change_type, and those are the fields to use when checking whether older table versions are leaking into the result. A row with date_extraction = 2026-04-05&amp;nbsp;can still legitimately appear in commit version 25 if version 25 updated or re-emitted that row.&lt;/P&gt;
&lt;P&gt;From your screenshot, DESCRIBE HISTORY shows versions 22, 23, 24, and 25 all as STREAMING UPDATE, each with the same numOutputRows = 8676. That pattern suggests the pipeline may be rewriting or updating the entire set of rows on each refresh, rather than appending a single new date_extraction value. In that case, seeing multiple date_extraction values in the output of table_changes(..., 25) would not necessarily mean older commit versions are being returned.&lt;/P&gt;
&lt;P class="wnfdntt _1ibi0s3f5 _1ibi0s3ce _1ibi0s3ea"&gt;Can you check the CDF metadata directly with something like this...&lt;/P&gt;
&lt;PRE class="_1ibi0s3d1" dir="auto"&gt;&lt;CODE class="language-sql"&gt;SELECT
  _commit_version,
  _change_type,
  _commit_timestamp,
  date_extraction,
  count(*) AS n
FROM table_changes('mytable', 25)
GROUP BY 1, 2, 3, 4
ORDER BY 1, 2, 4;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that query shows only _commit_version &amp;gt;= 25, then table_changes is behaving as documented, and what you’re seeing is most likely older business dates being touched again by commit 25 rather than old table versions being returned.&lt;/P&gt;
&lt;P&gt;If it shows any _commit_version &amp;lt; 25, then that would look inconsistent with the documented semantics, and it would be worth opening a support case or filing a bug with a minimal repro. For reference, the public docs for &lt;A href="https://docs.databricks.com/aws/en/sql/language-manual/functions/table_changes" rel="noopener noreferrer nofollow" target="_blank"&gt;table_changes&lt;/A&gt; and &lt;A href="https://docs.databricks.com/aws/en/tables/features/change-data-feed" rel="noopener noreferrer nofollow" target="_blank"&gt;Change Data Feed&lt;/A&gt; both describe the start version as inclusive and the no-end form as "from start to latest."&lt;/P&gt;
&lt;P class="p1"&gt;&lt;FONT size="2" color="#FF6600"&gt;&lt;STRONG&gt;&lt;I&gt;If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.&lt;/I&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;I&gt;&lt;/I&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2026 20:32:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/select-table-changes-return-unexpected-results/m-p/162284#M55059</guid>
      <dc:creator>Ashwin_DSA</dc:creator>
      <dc:date>2026-07-08T20:32:13Z</dc:date>
    </item>
  </channel>
</rss>

