Create a Simple PostgreSQL Function
📖 Scenario: You are working as a database assistant for a small bookstore. The store wants to have a quick way to calculate the total price of books including tax.
🎯 Goal: Build a PostgreSQL function named calculate_total_price that takes a book price as input and returns the price including a fixed tax rate.
📋 What You'll Learn
Create a function named
calculate_total_priceThe function should accept one parameter named
price of type numericThe function should return a
numeric valueInside the function, calculate the total price by adding 10% tax to the input price
Use the
LANGUAGE plpgsql syntax for the function💡 Why This Matters
🌍 Real World
Functions in databases help automate calculations like pricing, taxes, and discounts, saving time and reducing errors.
💼 Career
Knowing how to write database functions is useful for database administrators, backend developers, and data analysts to implement business logic inside the database.
Progress0 / 4 steps