<?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>
    <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/162372#M55068</link>
      <description>&lt;P class=""&gt;&lt;SPAN&gt;Thank you, Ashwin, for looking into my question.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN&gt;My table is appended whenever a new file arrives. Each file contains the same number of records (8,676), but with a different extraction date.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regarding the results of your query above, two additional files have been appended since version 25.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;_commit_version _change_type _commit_timestamp date_extraction n&lt;BR /&gt;25 insert 2026-07-08T15:01:20.000+00:00 2026-04-09 8676&lt;BR /&gt;26 insert 2026-07-08T19:49:47.000+00:00 2026-04-10 8676&lt;BR /&gt;27 insert 2026-07-09T12:51:10.000+00:00 2026-04-11 8676&lt;/P&gt;&lt;P&gt;When I run query below, I expect to see two rows, without extraction_date = '2026-04-09', however it returns three rows, including version 25.&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;LI-CODE lang="markup"&gt;SELECT
  date_extraction,
  count(*) AS n
FROM table_changes('duh_dev_bronze.sibl.cup_rate', 26)
GROUP BY 1
ORDER BY 1;

date_extraction	n
2026-04-09	8676
2026-04-10	8676
2026-04-11	8676&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jul 2026 14:46:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/select-table-changes-return-unexpected-results/m-p/162372#M55068</guid>
      <dc:creator>hdu</dc:creator>
      <dc:date>2026-07-09T14:46:34Z</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/163585#M55157</link>
      <description>&lt;P&gt;&amp;nbsp;Perhaps you try running one more variation?&lt;BR /&gt;&lt;BR /&gt;Your second query groups by date_extraction only which is a business column, so it can't tell us which commit those rows came from. Seeing the 2026-04-09 rows doesn't yet prove the result contains version 25. It could equally mean a commit at or after version 26 wrote rows carrying that older date. The same query with the version column visible would settle it:&lt;/P&gt;&lt;P&gt;```sql&lt;BR /&gt;SELECT _commit_version, _change_type, date_extraction, count(*) AS n&lt;BR /&gt;FROM table_changes('duh_dev_bronze.sibl.cup_rate', 26)&lt;BR /&gt;GROUP BY ALL&lt;BR /&gt;ORDER BY 1;&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;If the 04-09 rows come back with a _commit_version of 26 or higher, the feed is fine and something wrote that older date again after your first check. Worth asking then is whether the source file was re-uploaded or modified (a stream with allowOverwrites picks it up again), whether a backfill ran, or whether the streaming table was full refreshed, which rewrites every row under new versions and would also explain your original observation that after some time "all versions" seem to come back.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2026 03:16:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/select-table-changes-return-unexpected-results/m-p/163585#M55157</guid>
      <dc:creator>binlogreader</dc:creator>
      <dc:date>2026-07-21T03:16:49Z</dc:date>
    </item>
  </channel>
</rss>

