Thanks Pavel! Yes, faster, less code and much more readable.
CREATEORREPLACEFUNCTIONposts_by_user_dml()RETURNSTRIGGERAS$$begin-- delete entries for old values of tag_idsdeletefromposts_by_tagtwheret.tag_id=any(old.tag_ids)andt.user_id=old.user_idandt.post_id=old.post_id;-- insert entries for new values of tag_idsinsertintoposts_by_tag(tag_id,user_id,post_id,created_date)selectunnest(new.tag_ids),new.user_id,new.post_id,new.created_date;-- delete entries for old values of group_idsdeletefromposts_by_grouptwheret.group_id=any(old.group_ids)andt.user_id=old.user_idandt.post_id=old.post_id;-- insert entries for new values of group_idsinsertintoposts_by_group(group_id,user_id,post_id,created_date)selectunnest(new.group_ids),new.user_id,new.post_id,new.created_date;returnnew;end;$$LANGUAGEplpgsql;
I removed the test on null by the same occasion as this should not be aa general case so we have the beauty of SQL only :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks Pavel! Yes, faster, less code and much more readable.
I removed the test on null by the same occasion as this should not be aa general case so we have the beauty of SQL only :)