There are various methods for cloning/copying tables with SQL, but not all methods are supported by all RDBMSs.
Below are two options for cloning a table in SQL Server.
Continue readingThere are various methods for cloning/copying tables with SQL, but not all methods are supported by all RDBMSs.
Below are two options for cloning a table in SQL Server.
Continue readingIn PostgreSQL, we can use the RETURNING
clause to return data that was modified during an UPDATE
, INSERT
, or DELETE
operation. This allows us to see the data that was modified without having to perform a separate query to retrieve that data.
In SQL Server, we can use sequences to generate sequence numbers that increment by a specified amount. This means that any new number generated by the sequence will be the next sequential increment as specified in the sequence’s definition.
Normally, this is exactly what we want. We want each number to adhere to the increment that we specified when defining the sequence.
But what if we want to reset the sequence, so that the numbering starts all over again? In other words, we want to restart the sequence from the beginning. Or what if we want to reset the sequence so that it increments in a different range?
Fortunately, we can reset a sequence with the ALTER SEQUENCE
statement.
If you’re getting an error that reads “WRONGTYPE Operation against a key holding the wrong kind of value” when using the Redis HSTRLEN
command, it’s probably because you’re running the command against a key that doesn’t contain a hash.
If you’re getting an error that reads “ERR syntax error” when using the HRANDFIELD
command in Redis, it could be that you’re passing the wrong number of arguments. At the time of writing, the HRANDFIELD
command requires at least one argument, and accepts up to three arguments.
Redis provides some easy ways to check whether or not a field exists in a given hash. Here are five commands that we can use to check for the existence of a field in a given hash.
Continue readingIn PostgreSQL, the DATE_BIN()
function enables us to “bin” a timestamp into a given interval aligned with a specific origin. In other words, we can use this function to map (or force) a timestamp to the nearest specified interval.
This can be handy when we want to truncate a timestamp to a given interval, for example a 10 minute interval. We can specify the interval (e.g. 10 minutes, 15 minutes, 30 minutes, etc), and we can specify the starting point for the interval. Therefore, we can have the interval starting at any odd time we want (it doesn’t need to start on the hour or anything like that).
Continue readingThe following commands can be used to update a field in a Redis hash. The command we use will depend on the type of data that’s stored in the field.
Continue readingIn Redis, we can use the HRANDFIELD
command to return random fields from a given hash. By default, only the field names are returned.
But what if we want to include the field values?
In this case, we can use the WITHVALUES
option when calling the command.
MySQL provides us with several ways to copy a database table. The method we use will depend on our requirements.
We can choose to copy the table, its data, and its indexes. Or we can copy just the table and data without the indexes. We can alternatively generate the code that will enable us to copy the table later.
Continue reading