Stored Procedures
Procedure vs. Function
Basic Syntax
CREATE OR REPLACE PROCEDURE archive_old_orders(cutoff_date DATE)
LANGUAGE plpgsql
AS $$
BEGIN
-- Move data to archive
INSERT INTO orders_archive
SELECT * FROM orders WHERE order_date < cutoff_date;
-- Delete from main table
DELETE FROM orders WHERE order_date < cutoff_date;
-- We can commit here to free up locks!
COMMIT;
END;
$$;Key Procedural Logic (PL/pgSQL)
Why Data Engineers Use Procedures
Visualizing Procedure Execution
Summary
Last updated