In PostgreSQL, the CASE
expression compares a list of conditions and returns one of multiple possible result expressions.
The CASE
expression is included in the SQL standard (ISO/IEC 9075), and most major RDBMSs support it.
In PostgreSQL, the CASE
expression compares a list of conditions and returns one of multiple possible result expressions.
The CASE
expression is included in the SQL standard (ISO/IEC 9075), and most major RDBMSs support it.
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 readingMany SQL databases have a SUBSTR()
or equivalent function that returns a substring from a specified string.
Redis has a SUBSTR
command, but it was deprecated in Redis 2.0.0.
However, Redis also has the GETRANGE
command, that basically does the same thing. Basically, anything that was possible with the Redis SUBSTR
command, is now possible with the GETRANGE
command.
And the GETRANGE
command does basically the same thing that most of the SUBSTR()
and SUBSTRING()
functions do in the SQL world – gets a substring from a string.
There are several ways to return a key’s expiry in Redis. The method used depends on how we want the expiry to be returned.
We can use the TTL
command to return the timeout in seconds. We can alternatively use the PTTL
command to return it in milliseconds. Another way to do it is to use the EXPIRETIME
which returns the absolute Unix timestamp of the key in seconds, or the PEXPIRETIME
command which returns the absolute Unix timestamp of the key in milliseconds.
Here are examples of using SQL to return rows that contain non-alphanumeric characters in various DBMSs.
Non-alphanumeric characters include punctuation characters like !@#&()–[{}]:;',?/*
and symbols like `~$^+=<>“
, as well as whitespace characters like the space or tab characters.
In Redis, the OBJECT ENCODING
command returns the internal encoding for the Redis object stored at the specified key.
The INCR
command is commonly used in Redis to increment a value by one. And the INCRBY
command can be used to increment a valued by a specified integer. But neither of those commands let us work with floating point numbers.
If we want to use floating point numbers, we can use the INCRBYFLOAT
command.
In Redis, the RANDOMKEY
command returns a random key from the currently selected database.
Redis provides us with a convenient way to set multiple strings at once. Specifically, the MSET
command enables us to set multiple strings in one go.
There’s also the MSETNX
command which does the same thing, but only if none of the keys already exist.
Here are a couple of options for getting a list of tables in a database in PostgreSQL.
The first option is a psql
command, the second involves querying an information schema view.