Get startedGet started for free

The TRIM function

In this exercise, we are going to revisit and combine a couple of exercises from earlier in this chapter. If you recall, you used the LEFT() function to truncate the description column to 50 characters but saw that some words were cut off and/or had trailing whitespace. We can use trimming functions to eliminate the whitespace at the end of the string after it's been truncated.

This exercise is part of the course

Functions for Manipulating Data in PostgreSQL

View Course

Exercise instructions

  • Convert the film category name to uppercase and use the CONCAT() concatenate it with the title.
  • Truncate the description to the first 50 characters and make sure there is no leading or trailing whitespace after truncating.

Hands-on interactive exercise

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

-- Concatenate the uppercase category name and film title
SELECT 
  ___(___(___), ': ', ___) AS film_category, 
  -- Truncate the description remove trailing whitespace
  ___(___(___, ___)) AS film_desc
FROM 
  film AS f 
  INNER JOIN film_category AS fc 
  	ON f.film_id = fc.film_id 
  INNER JOIN category AS c 
  	ON fc.category_id = c.category_id;
Edit and Run Code