In PostgreSQL, we can use the substring()
function to extract the first substring matching the specified POSIX or SQL regular expression.
A Quick Look at PostgreSQL’s REGEXP_COUNT() Function
In PostgreSQL, the regexp_count()
function returns the number of times a given POSIX regular expression pattern matches in a given string.
We pass the string and pattern as arguments. We can also pass an argument to specify where to start the search. Additionally, we also have the option of specifying a flag that changes the function’s behaviour.
Continue readingUnderstanding the QUOTE_LITERAL() Function in PostgreSQL
In PostgreSQL, we can use the quote_literal()
function to quote strings within a SQL statement string.
Any embedded single-quotes and backslashes are properly doubled.
Continue readingFix “source array too small” When Updating an Array in PostgreSQL
If you’re getting an error that reads “source array too small” when updating an array in PostgreSQL, it’s probably because you’re passing a slice that’s smaller than your specified range. For example, if you specify a range that covers four elements but provide an array that contains just three elements, then you’d get this error.
To fix the error, be sure to provide an an array that contains at least as many elements as are specified in the range.
Continue readingHow the QUOTE_NULLABLE() Function Works in PostgreSQL
In PostgreSQL, the quote_nullable()
function returns a given string suitably quoted to be used as a string literal in a SQL statement string. It returns the actual string NULL
if the argument is null
.
Any embedded single-quotes and backslashes are properly doubled.
Continue readingFix “function array_shuffle(integer, integer) does not exist” in PostgreSQL
If you’re getting an error that reads “function array_shuffle(integer, integer) does not exist” when using the array_shuffle()
function in PostgreSQL, it’s probably because the argument you’re passing to the function is not an array.
Actually, the error message implies that you’re passing multiple integer values (two in this case, but it could be more), separated by a comma. Perhaps you’re trying to pass an array of integers, but you haven’t provided them in an array. Or perhaps you’re passing the wrong column or variable. Either way, the argument for this function must be an array.
To fix this error, replace the integer values with a single array value when calling the array_shuffle()
function.
2 Ways to View an Event’s Comment in MySQL
When we create a scheduled event in MySQL, we have the option of adding a comment to the event. This comment can be a string of up to 64 characters. We have a couple of options when it comes to viewing the comment of an existing event.
Continue readingA Quick Look at the OVERLAY() Function in PostgreSQL
In PostgreSQL, we can use the overlay()
function to replace a substring within a string. The function allows us to be very specific with regards to where in the string to start the operation and how much of it should be replaced.
Difference Between ARRAY_POSITIONS() and ARRAY_POSITION() in PostgreSQL
PostgreSQL has a couple of functions that enable us to get the position or positions of a given value in an array. One of them – array_position()
– returns the position of just the first occurrence (as an integer), while the other function – array_positions()
– returns the position of all occurrences (as an array).
So these functions are aptly named – one is singular and the other is plural.
But this isn’t the only difference. The array_position()
function allows us to specify a start position, while array_positions()
doesn’t.
Fix Error “op ANY/ALL (array) requires array on right side” in PostgreSQL
If you’re getting a PostgreSQL error that reads “op ANY/ALL (array) requires array on right side” it’s probably because you’re passing a non array to the ANY()
or ALL()
construct.
These constructs require an array to be included in the parentheses, and so passing a non array returns an error.
To fix this issue, be sure to pass an array when using these functions.
Continue reading