Hello Community,
I have the following situation:
In our project we have some config type: operations scripts that get executed every day.
They are merge scripts like the following:
Solved! Go to Solution.
The below script accounts for when there's no data to merge, while still ensuring the successful execution and dependency flow of your operations:
config {
type: "operations",
dependencies: ["dependecy1", "dependecy2"],
tags: ["deltaLoad"]
}
DECLARE deltaLoadTimestamp TIMESTAMP;
DECLARE deltaLoadDate DATE;
SET deltaLoadTimestamp = CURRENT_TIMESTAMP;
SET deltaLoadDate = ${functions.getDeltaLoadDate()};
-- Check ingestion status directly
IF (SELECT COUNT(*) FROM ${ref("ingestion_status_table")} WHERE ingestion_date = CURRENT_DATE()) > 0 THEN
MERGE INTO ${ref("aTable")} AS target
USING (
SELECT *
FROM ${ref("anotherTable")} t1
WHERE conditions
) AS source
ON CONDITIONS
WHEN MATCHED THEN
UPDATE SET COLUMNS
WHEN NOT MATCHED THEN
INSERT COLUMNS
VALUES();
ELSE
-- Silent exit with successful execution signal
SELECT 1;
END IF;
ingestion_status_table
to see if there's an entry for the current date.MERGE
operation proceeds as usual.ELSE
block executes a simple SELECT 1;
statement, effectively indicating a successful script run without any data modifications.