From the course: Advanced SQL for Data Scientists

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Write a user-defined function

Solution: Write a user-defined function

From the course: Advanced SQL for Data Scientists

Start my 1-month free trial

Solution: Write a user-defined function

(upbeat music) - [Narrator] This is our solution to the challenge to create a function called is_palindrome, which returns True when a string that's passed in is the same in reverse as it is going forward. You'll notice, we specify our create or replace function. Then we have our signature, followed by our function name, which in this case is, is_palindrome. We have a single parameter called STR, which is a type text and the function returns a Boolean. Then we specify the body of the function. Here, it's pretty straightforward. We're just going to use the reverse function. We're going to take the string, reverse it and see if it's equal to the string that was passed in. The other thing I want to point out is that because this function will always return the same value under any conditions, what if the parameter is the same at any time in the future? The results would always be the same. That means we can specify that this…

Contents