clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2591575 fiddles created (45741 in the last week).

CREATE Table a ("a_id" INT, "a_is_active" Boolean)
 hidden batch(es)


CREATE Table b ("b_id" INT, "b_is_active" Boolean)
 hidden batch(es)


CREATE Table ab ("ab_id" INT , "a_id" int, "b_id" int, "ab_is_active" Boolean)
 hidden batch(es)


INSERT INTO a VALUES (1,TRUE)
1 rows affected
 hidden batch(es)


INSERT INTO B VALUES (1,TRUE)
1 rows affected
 hidden batch(es)


INSERT INTO ab VALUES (1,1,1,FALSE)
1 rows affected
 hidden batch(es)


DO $BODY$ DECLARE b_is_active boolean; r ab%ROWTYPE; BEGIN for r in select ab.ab_id, ab.b_id,ab.a_id,_a.a_is_active AND _b.b_is_active AS ab_is_active from ab join b _b on ab.b_id= _b.b_id join a _a on ab.a_id= _a.a_id LOOP update ab set ab_is_active = r.ab_is_active where b_id = r.b_id AND a_id = r.a_id; END LOOP; END; $BODY$;
 hidden batch(es)


SELECT * FROM ab
ab_id a_id b_id ab_is_active
1 1 1 t
 hidden batch(es)


DO $BODY$ DECLARE b_is_active boolean; r ab%ROWTYPE; BEGIN for r in select ab.ab_id, ab.b_id,ab.a_id,_a.a_is_active AND _b.b_is_active AS ab_is_active from ab join b _b on ab.b_id= _b.b_id join a _a on ab.a_id= _a.a_id LOOP update ab set ab_is_active = r.ab_is_active where ab_id = r.ab_id; END LOOP; END; $BODY$;
 hidden batch(es)