Understanding Composite Types in PostgreSQL

In PostgreSQL, a composite type is a kind of data type that consists of multiple data types. It consists of a list of field names and their respective data types.

We can use composite types to fit multiple fields into one column.

We can create our own custom composite types, and they can be used in many of the same scenarios that simple data types can be used.

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

Using REGEXP_SPLIT_TO_ARRAY() in PostgreSQL

In PostgreSQL, the regexp_split_to_array() function splits a string using a POSIX regular expression as the delimiter, and returns the result in a text array.

So we use a POSIX regular expression to specify the delimiter/s, and split the string based on that.

We pass the string as the first argument and the pattern as the second. We can also specify a flag to determine how the function behaves.

Continue reading

How REGEXP_SPLIT_TO_TABLE() Works in PostgreSQL

In PostgreSQL, the regexp_split_to_table() function splits a string using a POSIX regular expression as the delimiter, and returns the result in a table.

So we use a POSIX regular expression to specify the delimiter/s, and split the string based on that.

We pass the string as the first argument and the pattern as the second. We can also specify a flag to change the behaviour of the function.

Continue reading

Understanding PostgreSQL’s LOG10() Function

In PostgreSQL, log10() is a mathematical function that returns the base 10 logarithm of its argument.

It was added in PostgreSQL 12 as a SQL-standard equivalent of the existing log() function.

There is a difference between the two functions though, because log() allows us to specify which base to use (although it defaults to base 10), whereas log10() uses base 10 only.

Continue reading