A Quick Look at the LEFT() Function in PostgreSQL

In PostgreSQL we can use the left() function to get the specified number of leftmost characters in a given string.

We have the option of specifying the number of characters to return from the left or the number of characters to omit from the right. We do this by specifying a positive integer (to return n number of leftmost characters) or a negative integer (to return everything except n rightmost characters).

Continue reading

How REGEXP_REPLACE() Works in PostgreSQL

In PostgreSQL, we can use the regexp_replace() function to replace a substring within a given string, based on a given POSIX regular expression. We can specify that all matches are replaced or just the first match.

We pass the string as the first argument, the pattern as the second, and the replacement text as the third argument. We also have the option of specifying the start position as the fourth argument, and we can specify a flag to determine how the function behaves.

Continue reading

Understanding PostgreSQL’s TRANSLATE() Function

PostgreSQL has a translate() function which replaces certain characters in a string with certain other characters.

We specify the characters in the string that we want to replace, as well as the characters that we want to replace them with. The function then performs the translation and returns the string with the replaced characters.

Continue reading