Determining the length of strings
Determining the number of characters in a string is something that you will use frequently when working with data in a SQL database. Many situations will require you to find the length of a string stored in your database. For example, you may need to limit the number of characters that are displayed in an application or you may need to ensure that a column in your dataset contains values that are all the same length. In this example, we are going to determine the length of the description
column in the film
table of the DVD Rental database.
This exercise is part of the course
Functions for Manipulating Data in PostgreSQL
Exercise instructions
- Select the
title
anddescription
columns from thefilm
table. - Find the number of characters in the
description
column with the aliasdesc_len
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
SELECT
-- Select the title and description columns
___,
___,
-- Determine the length of the description column
___(___) AS ___
FROM film;