How to: check for special characters or non-alphanumeric characters in a string when working with Netezza SQL.
About
The below SQL is one way you can check for the presence of special characters in a string returning true or false. You can see that we define special characters as non-alphanumeric characters in both upper and lower case (the second argument to the translate() function) and we include a space. If this does not suit your purposes it is easily modified.
Code
Below is example SQL code where we return true or false depending on the content of the input string (argument 1) to the translate() function.
result: TRUE
Explanation
Using the built in translate() function we remove all the caracters from the string we consider alphanumerics (argument 2) and then count the length of the remaining string. If it is 1 or more then we have characters remaining and the case when
statement retuns true.