Instruction
Typically, functions are more complex and can contain multiple INSERT, UPDATE, and/or DELETE operations, as shown in the example below:
CREATE FUNCTION remove_product(prod_id smallint)
RETURNS void AS $$
BEGIN
UPDATE product
SET
is_available = false,
is_active = false
WHERE product_id = prod_id;
DELETE FROM prod_inventory
WHERE product_id = prod_id;
END;
$$ LANGUAGE plpgsql;
The function above updates a product with a given ID and sets its attributes (is_available and is_active) to false. It also deletes the product from the product inventory.
Exercise
Implement a new function named remove_user_account() that has one argument: user_account_id, of type integer.
This function will do the following operations:
- Update the record in the
user_accounttable with a given ID (user_account_id), set theis_deletedflag to true, and set thedeleted_dateto thecurrent_datevalue. - Mark all users' posts as deleted: update all user's posts (based on a given ID) in the
posttable, set the post'sis_deletedflag to true, and set thedeleted_timestampto thecurrent_timestampvalue.



