DO $$ 
declare
    test_date date := '2023-04-10';
    building_time interval;
    cq record;
begin 
    FOR cq IN SELECT * FROM constructionqueue LOOP
        SELECT build_time INTO building_time FROM buildingcost WHERE building_id = cq.building_id;
        IF cq.start_date + building_time > test_date THEN
            INSERT INTO basebuilding VALUES(cq.building_id, cq.base_id);
            DELETE FROM constructionqueue WHERE construction_id = cq.construction_id;
        END IF;
    END LOOP;
END $$;