Understanding PostgreSQL’s REGEXP_MATCHES() Function

In PostgreSQL, the regexp_matches() function returns substrings that match a given POSIX regular expression in a given string. We can specify that all matches are returned or just the first match. If all matches are returned, each is returned in a separate row.

We pass the string as the first argument and the pattern as the second argument. We can also provide a flag as an optional third argument, which determines how the function behaves.

Each returned row is a text array containing the whole matched substring or the substrings matching parenthesised subexpressions of the pattern.

Continue reading

How REGEXP_MATCH() Works in PostgreSQL

In PostgreSQL, the regexp_match() function returns a text array containing substrings that match a given POSIX regular expression in a given string. Only the first match is returned (to return all matches, use regexp_matches() instead).

We pass the string as the first argument and the pattern as the second argument. We can also provide a flag as an optional third argument, which determines how the function behaves.

Continue reading

How PostgreSQL’s CHARACTER_LENGTH() Function Works

In PostgreSQL, we can use the character_length() function to return the number of characters in a given string.

It accepts one argument; the string for which to return the length.

The character_length() function is a synonym for the char_length() function and so both do the same thing. We can also use the length() function to get the same result.

Continue reading