05-27-2024 05:00 AM
According to the documentation the WHERE predicate in a DELETE statement should supports subqueries, including IN, NOT IN, EXISTS, NOT EXISTS, and scalar subqueries.
if I try to run a query like:
DELETE FROM dev.gold.table AS trg
WHERE EXISTS (
select distinct year_month, version
from source
where trg.year_month = year_month
and trg.version = version
)
I get the error:
[DELTA_NESTED_SUBQUERY_NOT_SUPPORTED] Nested subquery is not supported in the DELETE condition.
Same error if I use IN after grouping the year_month and version into a single column:
DELETE FROM dev.gold.table AS trg
WHERE year_month_version IN (select * FROM v_distinct_year_month_version)
Any solution, other than a merge delete, to solve the problem?
I'm running a SQL notebook with serverless warehouse.
05-27-2024 10:48 PM
05-27-2024 06:54 AM
@diego_poggioli
What is the "source" in your WHERE statement? Is it a table or a view/temp view?
05-27-2024 07:50 AM - edited 05-27-2024 08:03 AM
@daniel_sahal currently is a temp view
05-27-2024 10:48 PM
05-28-2024 12:04 AM
Yes, correct! using a table instead of a view fixed the error
Thanks
05-27-2024 10:42 AM - edited 05-27-2024 10:47 AM
Can you try selecting a 'year_month_version' column from the view instead of select *
DELETE FROM dev.gold.table AS trg
WHERE year_month_version IN (select year_month_version FROM v_distinct_year_month_version)
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group