PostgreSQL sometimes provides us with multiple functions that basically do the same thing. Such is the case with the following two functions that return the position of a given substring within a string.
PostgreSQL
A Quick Look at TO_HEX() in PostgreSQL
In PostgreSQL, we can use the to_hex() function to convert a number to its equivalent hexadecimal representation.
The function accepts the number as an integer or bigint, and it returns the result as a text representation of its hexadecimal equivalent.
How to Specify your own Subscript Range when Creating an Array in PostgreSQL
By default, PostgreSQL arrays are one-based. This means that we need to use 1 if we want to reference the first element in the array, 2 for the second, and so on.
But we also have the option of specifying our own subscript range for an an array. For example we could create a zero-based array, a ten-based array, or even a negative value such as a negative ten-based array.
We can do this by using subscripted assignment to specify the actual subscript range for the array. Basically, we prefix the array with the subscript range, enclosed in square brackets, and an equals sign (=) between it and the array.
A Quick Look at the ASCII() Function in PostgreSQL
In PostgreSQL, we can use the ascii() function to get the numeric code of the first character of the argument.
When using UTF8, the function returns the Unicode code point of the character. Other multibyte encodings require an ASCII character.
Understanding PostgreSQL’s SPLIT_PART() Function
The PostgreSQL split_part() function splits a string based on a specified delimiter and then returns the specified part from the split string.
The function accepts three arguments; the string, the delimiter, and the part that we want to return.
A Quick Look at PostgreSQL’s PG_CLIENT_ENCODING() Function
In PostgreSQL, we can use the pg_client_encoding() function to get the current client encoding name.
Understanding the RIGHT() Function in PostgreSQL
In PostgreSQL the right() function returns the specified number of rightmost characters in a given string.
We have the option of specifying the number of characters to return from the right or the number of characters to omit from the left. We do this by specifying a positive integer (to return n number of rightmost characters) or a negative integer (to return everything except n leftmost characters).
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).
A Quick Overview of the ERFC() Function in PostgreSQL
In PostgreSQL, erfc() is a mathematical function that provides the mathematical complementary error function, without loss of precision for large inputs. It returns 1 - erf(x).
The erfc() function was introduced in PostgreSQL 16, which was released on September 14th 2023.
How to Specify Sequence Options for IDENTITY Columns in PostgreSQL
When we create an IDENTITY column in PostgreSQL, we have the option of specifying our own values for the sequence object that’s created.
This article provides an example of creating an IDENTITY column with our own sequence options.