Get startedGet started for free

User-defined functions in Sakila

If you were running a real-life DVD Rental store, there are many questions that you may need to answer repeatedly like whether a film is in stock at a particular store or the outstanding balance for a particular customer. These types of scenarios are where user-defined functions will come in very handy. The Sakila database has several user-defined functions pre-defined. These functions are available out-of-the-box and can be used in your queries like many of the built-in functions we've learned about in this course.

In this exercise, you will build a query step-by-step that can be used to produce a report to determine which film title is currently held by which customer using the inventory_held_by_customer() function.

This exercise is part of the course

Functions for Manipulating Data in PostgreSQL

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

-- Select the film title and inventory ids
SELECT 
	f.___, 
    i.___
FROM ___ AS f 
	-- Join the film table to the inventory table
	INNER JOIN ___ AS i ON f.___=i.___ 
Edit and Run Code