clear markdown compare help donate comments/suggestions/bugs a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith?
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0

CREATE TABLE master ( m_id INTEGER, m_value VARCHAR(4) );
 hidden batch(es)


CREATE TABLE scheduled ( key INTEGER, s_id INTEGER, s_value VARCHAR(4), due TIMESTAMP );
 hidden batch(es)


INSERT INTO master VALUES (1, 'Buy');
 hidden batch(es)


INSERT INTO master VALUES (2, 'Buy');
 hidden batch(es)


INSERT INTO scheduled VALUES (1, 1, 'Sell', '2018-01-01 12:00:00');
 hidden batch(es)


INSERT INTO scheduled VALUES (2, 2, 'Sell', '2018-01-01 12:00:01');
 hidden batch(es)


INSERT INTO scheduled VALUES (3, 1, 'Buy', '2019-01-01 12:00:00');
 hidden batch(es)


SELECT * FROM master;
m_id m_value
1 Buy
2 Buy
 hidden batch(es)


SELECT * FROM scheduled;
key s_id s_value due
1 1 Sell 2018-01-01 12:00:00
2 2 Sell 2018-01-01 12:00:01
3 1 Buy 2019-01-01 12:00:00
 hidden batch(es)


BEGIN;
 hidden batch(es)


UPDATE master SET m_value = ( SELECT s_value FROM scheduled s WHERE s_id = m_id AND due <= CURRENT_DATE );
 hidden batch(es)


DELETE FROM scheduled WHERE s_id IN (SELECT m_id FROM master) AND s_value = 'Sell';
 hidden batch(es)


SELECT * FROM scheduled;
key s_id s_value due
3 1 Buy 2019-01-01 12:00:00
 hidden batch(es)


COMMIT;
 hidden batch(es)


SELECT * FROM master;
m_id m_value
1 Sell
2 Sell
 hidden batch(es)