Recall & Review
beginner
What does a PostgreSQL function returning TABLE do?
It returns a set of rows with defined columns, like a table, allowing you to get multiple rows and columns from a single function call.
Click to reveal answer
beginner
How do you define the columns returned by a function returning TABLE in PostgreSQL?
You specify the column names and their data types in the RETURNS TABLE clause of the function definition.
Click to reveal answer
intermediate
What SQL statement inside a function returning TABLE provides the rows to return?
A RETURN QUERY statement is used to return the rows from a SELECT or other query inside the function.
Click to reveal answer
intermediate
Can a function returning TABLE be used in a FROM clause like a regular table?
Yes, you can call the function in the FROM clause and treat its output like a table to join or filter results.
Click to reveal answer
advanced
What is the benefit of using functions returning TABLE over returning SETOF RECORD?
Functions returning TABLE have named columns and types defined upfront, making them easier to use and safer because the output structure is fixed.
Click to reveal answer
Which keyword defines the columns and types a PostgreSQL function will return as a table?
✗ Incorrect
RETURNS TABLE specifies the column names and types the function will return as a table.
Inside a function returning TABLE, which statement returns the query result rows?
✗ Incorrect
RETURN QUERY returns the result of a query as the function output rows.
How can you use a function returning TABLE in a SQL query?
✗ Incorrect
Functions returning TABLE can be called in the FROM clause and treated like tables.
What is a key advantage of RETURNS TABLE over RETURNS SETOF RECORD?
✗ Incorrect
RETURNS TABLE explicitly defines output columns and types, making usage clearer and safer.
Which of these is a valid way to define a function returning TABLE in PostgreSQL?
✗ Incorrect
Option C correctly defines a function returning TABLE with columns and uses RETURN QUERY.
Explain how to create a PostgreSQL function that returns multiple rows and columns using RETURNS TABLE.
Think about how to define output columns and how to return query results inside the function.
You got /3 concepts.
Describe the difference between RETURNS TABLE and RETURNS SETOF RECORD in PostgreSQL functions.
Consider how output structure is handled in both cases.
You got /3 concepts.