Beginners-PostgreSQL Functions Explained | Create, Call & Automate with PL/pgSQL (Beginner to Pro)
Unlock the power of PostgreSQL with this easy, story-driven tutorial!
In this video, you’ll learn how to create, call, and combine functions and procedures — using real examples like calculating book profits.
Perfect for beginners who want to understand how SQL logic works behind the scenes.
What you’ll learn:
How to write and call PostgreSQL functions
The difference between functions and procedures
How to update tables using your own logic
Real-time examples with bookdetails table
Watch till the end for a clear explanation that feels like learning from a friend — not a textbook!
🔔 Subscribe for more tutorials
------------Query Used in Tutorial-------------
--Creating FUNCTION Query
CREATE OR REPLACE FUNCTION calculate_book_profit(
p_purchase_price NUMERIC,
p_selling_price NUMERIC,
p_discount_percent NUMERIC
)
RETURNS NUMERIC AS $$
BEGIN
RETURN (p_selling_price-(p_selling_price*p_discount_percent/100))-p_purchase_price;
END;
$$ LANGUAGE plpgsql;
-- Calling Function Query
SELECT book_name, purchase_price, selling_price, discount_percent, ROUND(calculate_book_profit(purchase_price, selling_price, discount_percent),2) AS real_time_profit
FROM bookdetails;