PostgreSQL has a bit_length()
function that returns the number of bits in a given string. We pass the string as an argument and the function returns the number of bits in that string.
Tag: what is
A Quick Intro to ARRAY_CAT() in PostgreSQL
In PostgreSQL, we can use the array_cat()
function to concatenate two arrays.
We pass both arrays as arguments when we call the function.
Continue readingUnderstanding the BTRIM() Function in PostgreSQL
PostgreSQL has a function called btrim()
that we can use to trim both sides of a string. We can trim blank spaces or we can specify certain characters to trim.
It removes the longest string containing only characters from the ones we specify. If we don’t specify any characters, then it removes blank spaces from both sides.
We provide the string as the first argument, and the (optional) characters as the second.
Continue readingHow ARRAY_PREPEND() Works in PostgreSQL
In PostgreSQL, the array_prepend()
function prepends an element to the start of an array.
The first argument is the element to prepend, and the second argument is the array.
Continue readingA Quick Look at ARRAY_APPEND() in PostgreSQL
In PostgreSQL, we can use the array_append()
function to append an element to the end of an array.
The first argument is the array, and the second argument is the element to append.
Continue readingA Quick Overview of the ARRAY_POSITIONS() Function in PostgreSQL
PostgreSQL has an array_positions()
function that returns the position of the all occurrences of a given value in an array.
There’s also a array_position()
function (singular) that returns the position of just the first occurrence. So to get just the first occurrence, use that function instead.
Using STRING_TO_TABLE() in PostgreSQL
In PostgreSQL, we can use the string_to_table()
function to return a set of rows, each containing a part of the string. The string is split based on the specified delimiter.
If we specify a null delimiter, then each character becomes a separate row in the output. If the delimiter string is empty, then the whole string is returned in a single row.
We also have the option of turning a specific substring into null
if required.
Using the ARRAY_LENGTH() Function in PostgreSQL
In PostgreSQL, the array_length()
function returns the length of the specified array dimension.
We pass the array as the first argument, and the dimension as the second.
Continue readingA Quick Overview of the CARDINALITY() Function in PostgreSQL
In PostgreSQL we can use the cardinality()
function to return the total number of elements in an array. This includes elements across all dimensions of the array.
We pass the array as an argument to the function, and it returns an integer of the total number of elements in that array.
Continue readingHow ARRAY_POSITION() Works in PostgreSQL
PostgreSQL has an array_position()
function that returns the position of the first occurrence of a given value in an array.
We have the option to specify a starting position, so that the function returns the position of the first occurrence after that.
To get all occurrences, use array_positions()
instead.