Autumn Offers - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Concatenation
Simple text functions
12. The TRIM() function
Modifying strings
Summary

Instruction

You now know two functions that remove either leading or trailing spaces. Sometimes you need to remove both leading and trailing spaces. With PostgreSQL, you can do this with the TRIM() function. It only requires one parameter. Take a look:

SELECT TRIM(' Martin Smith      from England   .   ');

After calling this function, you get:

'Martin Smith      from England   .'

Exercise

Remove all leading and trailing spaces from the item names in the item table. For each item, show the original item name (name the column before_trim) and the item name without leading and trailing spaces (name the column after_trim). In order to see the difference, put asterisks (*) on both sides of the value (using the concatenation operator).

Stuck? Here's a hint!

Use TRIM() with column name as an argument. Don't forget to concatenate the columns with asterisks on both sides: '*' || name || '*'.