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.
Este exercício faz parte do curso
Functions for Manipulating Data in PostgreSQL
Instruções do exercício
- Convert the film category
nameto uppercase and use theCONCAT()concatenate it with thetitle. - Truncate the description to the first 50 characters and make sure there is no leading or trailing whitespace after truncating.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
-- 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;