In Redis, the ZLEXCOUNT
command returns the number of elements in a sorted set with a value between two given values. It can be used when we force lexicographical ordering by applying the same score to all members of a sorted set.
How LAST_INSERT_ID() Works in MySQL
In MySQL, the LAST_INSERT_ID()
function returns the first automatically generated value successfully inserted for an AUTO_INCREMENT
column as a result of the most recently executed INSERT
statement.
It can also be called with an argument, in which case, it returns the value of the expression and the next call to LAST_INSERT_ID()
will return the same value.
Fix “Cannot DROP SEQUENCE ‘…’ because it is being referenced by object” in SQL Server
If you’re getting an error that reads something like “Cannot DROP SEQUENCE ‘Sequence2’ because it is being referenced by object ‘DF__Dogs__DogId__6C190EBB’“, it could be because you’re trying to drop a sequence object that’s referenced by a DEFAULT
constraint.
Sequences that are referenced by a DEFAULT
constraint can’t be dropped until the DEFAULT
constraint is dropped.
Therefore, to fix this issue, drop the DEFAULT
constraint first.
7 Functions that Separate Hours, Minutes, Seconds, & Microseconds from a Time Value in MySQL
Below are seven functions we can use to extract the hours, minutes, seconds, and microseconds from a time value in MySQL.
Continue readingHow GENERATE_SERIES() Works in PostgreSQL
In PostgreSQL, we can use the generate_series()
function to return a series of values between a given start and stop point. This can be a series of numbers or a series of timestamps.
The function returns a set containing the series.
Continue readingMySQL ICU_VERSION() Explained
In MySQL, the ICU_VERSION()
function returns the version of the International Components for Unicode (ICU) library used to support regular expression operations.
The ICU_VERSION()
function is primarily intended for use in test cases.
Fix “WRONGTYPE Operation against a key holding the wrong kind of value” when using ZREM in Redis
If you get an error that reads “WRONGTYPE Operation against a key holding the wrong kind of value” when using the ZREM
command in Redis, it’s because you’re passing a key with the wrong data type.
To fix this issue, make sure that you pass a sorted set to the ZREM
command.
2 Ways to Set a Maximum and/or Minimum Value when Creating a Sequence in SQL Server
By default, SQL Server sets its own minimum and maximum values for sequence objects based on the data type of the sequence object. Assuming we don’t set the data type for the sequence, these min/max values are based on the bigint data type (because that’s the default data type for sequence objects in SQL Server).
However, we can also set our own minimum and maximum values for our sequences. We can do this either explicitly (by setting the MAXVALUE
and MINVALUE
properties) or implicitly (by setting the data type).
Fix “START value (…) cannot be less than MINVALUE (…)” When Creating a Sequence in PostgreSQL
If you’re getting an error that reads something like “START value (0) cannot be less than MINVALUE (1)” in PostgreSQL when you’re trying to create a sequence, it’s because your sequence’s start value is lower than its minimum value, when it should be at least the same or higher.
To fix this issue, be sure that the sequence’s start value is at least the same or greater than the minimum value.
Continue readingHow CURRENT_ROLE() Works in MySQL
In MySQL, CURRENT_ROLE()
is a built-in function that returns the current active roles for the current session, separated by commas, or NONE
if there are none. The current role determines our access privileges.