Complete the code to create a trigger function that returns the new row.
CREATE FUNCTION trg_func() RETURNS trigger AS $$ BEGIN RETURN [1]; END; $$ LANGUAGE plpgsql;The trigger function must return NEW to indicate the new row after an insert or update.
Complete the code to specify the language of the trigger function as PL/pgSQL.
CREATE FUNCTION trg_func() RETURNS trigger AS $$ BEGIN RETURN NEW; END; $$ LANGUAGE [1];The trigger function language must be plpgsql for procedural SQL in PostgreSQL.
Fix the error in the trigger function header to correctly declare it returns a trigger.
CREATE FUNCTION trg_func() RETURNS [1] AS $$ BEGIN RETURN NEW; END; $$ LANGUAGE plpgsql;Trigger functions must return trigger type in PostgreSQL.
Fill both blanks to create a trigger function that logs the old and new values.
CREATE FUNCTION log_changes() RETURNS trigger AS $$ BEGIN RAISE NOTICE 'Old: %, New: %', [1], [2]; RETURN NEW; END; $$ LANGUAGE plpgsql;
The trigger function uses OLD and NEW to access the row before and after the change.
Fill all three blanks to create a trigger function that prevents deletion by raising an exception.
CREATE FUNCTION prevent_delete() RETURNS trigger AS $$ BEGIN IF TG_OP = [1] THEN RAISE EXCEPTION [2]; RETURN [3]; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql;
The function checks if the operation is DELETE, raises an exception with a message to prevent deletion, and returns OLD.