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

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

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

INSERT INTO master VALUES (1, 'Buy');

INSERT INTO master VALUES (2, 'Buy');

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

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

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

SELECT * FROM master;
m_id m_value
1 Buy
2 Buy

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

BEGIN;

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

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

SELECT * FROM scheduled;
key s_id s_value due
3 1 Buy 2019-01-01 12:00:00

COMMIT;

SELECT * FROM master;
m_id m_value
1 Sell
2 Sell