Create a PostgreSQL Function Returning a Table
📖 Scenario: You work in a small bookstore database. You want to create a function that returns a list of books with their titles and prices.
🎯 Goal: Build a PostgreSQL function named get_books that returns a table with columns title (text) and price (numeric).
📋 What You'll Learn
Create a table named
books with columns title (text) and price (numeric).Insert three specific books into the
books table.Create a function named
get_books that returns a table with columns title and price.The function should return all rows from the
books table.💡 Why This Matters
🌍 Real World
Functions returning tables are useful to package reusable queries that return multiple rows and columns, like reports or filtered data.
💼 Career
Database developers and backend engineers often write such functions to simplify complex queries and improve code reuse.
Progress0 / 4 steps