I have the following script where I need to find a given chapter, change the state, then store the activity reference to remove the activity later (because of the FK in chapter_published
activity), delete the chapter_published
reference and then use the id_activity
to finally remove the parent activity.
How would I do that programatically using a postgresql script in a very simple way? And where is that documented?
Below is an example of what I would be expecting to achieve:
-- Manually find the chapter I want first
select * from ws_chapter;
-- store the chapter once so I don't have to repeat in each statement
@chapter_id = 15;
-- Update the state field
update chapter set cd_state = 'DRAFT' where id_chapter = @chapter_id;
-- Now get the id of the activity for later use
@activity_id = select id_activity from chapter_published where id_chapter = @chapter_id;
-- Make the delete
delete from chapter_published where id_chapter = @chapter_id;
delete from activity where id_activity = @activity_id;