In SQLite, we can use the TIME()
function to subtract one or more seconds from a time value.
For datetime values, we can use the DATETIME()
function.
In SQLite, we can use the TIME()
function to subtract one or more seconds from a time value.
For datetime values, we can use the DATETIME()
function.
In Redis, we can use the STRLEN
command to get the length of a given string value, based on its key.
We can also use the HSTRLEN
command to get the string length of a value stored in a hash.
Redis provides us with quite a few options for setting keys and any timeouts associated with those keys. Sometimes we can do it with a single command, other times we need two commands.
Here are four ways to set a key and its expiry in Redis.
Continue readingThe following examples use SQL to delete duplicate rows that have a primary key or unique identifier column.
Specifically, the examples delete all duplicates except one. So for example, in the case of three identical rows, it deletes two of them and keeps one.
Continue readingIf we need to append a value to a string in Redis, we can use the APPEND
command to do just that. All we need to do is call the command with the key name and the value to append.
PostgreSQL has supported generated columns since version 12. Generated columns can be created easily with the CREATE TABLE
and ALTER TABLE
statements.
We can check whether a table contains a generated column or not with the following methods.
Continue readingWhen setting a timeout for a key in Redis, we have the option of setting it only if the key already has an expiry. So, if the key doesn’t already have an associated timeout, the new timeout won’t apply. The new timeout will only apply if the key already has an existing timeout. In such cases the expiry will be reset to the new expiry.
We can do this with the XX
option of the EXPIRE
command. We can also use the XX
option on commands such as EXPIREAT
, PEXPIRE
, and PEXPIREAT
.
If you’re trying to add a generated column in SQLite, and you’re getting the “cannot add a STORED column” error, it’s probably because you’re trying to add a stored column.
In SQLite, we can only add virtual columns to existing tables.
Continue readingIn Redis, the GET
command is typically used to return the value of a single key that holds a string. But what if we need the values from multiple keys?
We can use the MGET
command.
In Redis, we have several options for incrementing a key. For example, if we set a key to 1, we can increment it by 1 to make 2. Or we can increment it by whatever amount we desire.
Below are four ways to increment a key in Redis.
Continue reading