I need to insert values into a global table based on whether local table (which is updated everyday) is empty or not. So I tried this code, and it totally works if I replace the second SELECT statement with actual values, but those values will be changing every day, so I really need to find some workaound.
DO
'
BEGIN
IF ((SELECT count(*) FROM crit_crashes) > 0) THEN
INSERT INTO usr_wrk.crit_crashes (sd, title, business_line, start_dttm, end_dttm, category, date_opened) VALUES (SELECT * FROM crit_crashes);
ELSE
INSERT INTO usr_wrk.crit_crashes (sd, title, business_line, start_dttm, end_dttm, category, date_opened) VALUES (NULL, NULL, NULL, NULL, NULL, NULL, current_date);
END IF;
END;
'