PostgreSQL has a normalize()
function that converts a string to the specified Unicode normalization form.
The function can only be used when the server encoding is UTF8
.
PostgreSQL has a normalize()
function that converts a string to the specified Unicode normalization form.
The function can only be used when the server encoding is UTF8
.
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.
In PostgreSQL the length()
function returns the number of characters in a given string.
We pass the string as an argument and the function returns the number of characters as an integer.
Continue readingIn PostgreSQL, the char_length()
function returns the number of characters in a string. We pass the string as an argument and the function returns the number of characters in that string.
We can also use character_length()
and length()
to get the same result.
If you’re getting an error that reads something like ‘column “c1” cannot be cast automatically to type text[]‘ in PostgreSQL, it could be that you’re trying to change a column’s type to one where the existing type can’t be implicitly cast to.
To fix this issue, try explicitly casting the column to the desired data type.
Continue readingIn PostgreSQL, we can use the replace()
function to replace a given substring within a string with another substring.
The function replaces all occurrences of the substring. If the substring doesn’t exist in the string, then the original string is returned unchanged.
Continue readingIn PostgreSQL, string_to_array()
is a string function that allows us to create an array from a string. It splits the string based on the specified delimiter and returns a text
array as a result.
If we specify a null delimiter, then each character becomes an element in the array. If the delimiter string is empty, then the whole string becomes a single element in the array.
We also have the option of turning a specific substring into null
if required.
In PostgreSQL, the strpos()
function returns the first starting position of a given substring within a string.
We pass the string as the first argument and the substring as the second.
Continue readingIn PostgreSQL, we can use the the substr()
function to return a substring from a string, based on a starting point. We have the option of specifying how many characters to return.
We pass the string as the first argument and the start position as the second. If we want to specify how long the substring should be, we can pass a third argument that specifies how many characters to return.
The function returns the same result as the substring()
function (which uses a slightly different syntax).
If you’re getting an error that reads “function array_sample(numeric, integer) does not exist” when using the array_sample()
function in PostgreSQL, it’s probably because your first argument is a numeric type instead of an array.
The first argument for this function must be an array.
To fix this error, be sure that your first argument to array_sample()
is an array, not a numeric value.