What is the equivalent of "if exists()" in databricks sql?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 11:42 AM
What is the equivalent of the below sql server syntax in databricks sql? there are cases where i need to execute a block of sql code on certain conditions. I know this can be achieved with spark.sql, but the problem with spark.sql() is it does not provide the number of affected columns (insert/update/delete) after the execution of dml statement.
IF EXISTS(SELECT 1 FROM table WHERE col = value)
BEGIN
DELETE FROM table WHERE col = value
END
ELSE
BEGIN
<code to run in else>
END