PostgreSQL provides another function similar to
TRANSLATE(), and it looks like this:
TRANSLATE(string_to_search, old_characters, new_characters)
This function searches
string_to_search, which can be an actual string or a field in the database, for the characters in
old_characters. When it finds them, they're replaced with the corresponding characters in the
new_characters. Here's how it looks:
TRANSLATE(text, ' .', '*!') AS translated_text
This will change the
text of the slogans in the
slogan table. The characters we're replacing are
' .' – spaces and periods. We want to translate them to
'*!': all spaces are replaced with the asterisks and all dots are replaced with the exclamation marks. Look at the result:
||Feel the difference. Feel the powder.
||Get enthusiastic - even without alcohol.