In MySQL, we can use the SHOW CREATE TABLE
statement to generate a CREATE TABLE
script for existing tables. This enables us to recreate the table without having to manually type out the table’s definition.
Author: Ian
How JSON_TABLE() Works in MySQL
In MySQL, JSON_TABLE()
is a built-in function that converts JSON data into a relational form.
In other words, it lets you return a JSON document as a table.
The JSON_TABLE()
function was introduced in MySQL 8.0.
6 Ways to Fix “nextval: reached maximum value of sequence” in PostgreSQL
If you’re getting an error that reads something like “nextval: reached maximum value of sequence “sequence1” (3)” in PostgreSQL, it’s probably because you’re trying to generate a new value from a sequence, but the sequence has already reached its maximum value.
We have quite a few options when it comes to dealing with this issue.
Continue readingFix “WRONGTYPE Operation against a key holding the wrong kind of value” when using ZMPOP or BZMPOP in Redis
If you get an error that reads “WRONGTYPE Operation against a key holding the wrong kind of value” when using the ZMPOP
or BZMPOP
commands in Redis, it’s because you’re passing a key with the wrong data type.
To fix this issue, make sure you pass a sorted set to these commands.
Continue readingHow to Return the Result of FOR XML as XML Data Type in SQL Server
In SQL Server, when we use FOR XML
to return query results in an XML document, the resulting XML document is returned as a string by default. However, we can change this so that it’s returned in the xml data type.
To do this, all we need to do is append our query with the TYPE
directive.
Fix ‘currval of sequence “…” is not yet defined in this session’ When Calling CURRVAL() in PostgreSQL
If you’re getting an error that reads something like ‘currval of sequence “sequence1” is not yet defined in this session‘ when calling the currval()
function in PostgreSQL, it’s probably because nextval()
hasn’t yet been called for that sequence in the current session.
Add a Column that Cycles Through a Range of Numbers in a Result Set in SQL Server
If we ever need to assign repeating sequence numbers to a result set in SQL Server, we can use a sequence object with the appropriate arguments.
In particular, we can use the CYCLE
argument to specify that the sequence will cycle through the range of numbers. In other words, once it reaches the end of the sequence, it starts again, and will continue to reiterate every time it completes the sequence.
How CAST() Works in MySQL
In MySQL, CAST()
is a built in function that converts a value to another data type. It takes a value of one type and returns a value of the specified type.
You provide the value as an argument when you call the function, as well as the type that you’d like it converted to.
CAST()
works similar to CONVERT()
, except that the syntax used is slightly different.
Fix “ERROR 1298 (HY000): Unknown or incorrect time zone…” in MySQL
If you’re getting error 1298 that reads something like “ERROR 1298 (HY000): Unknown or incorrect time zone: ‘UTC’” in MySQL, it’s probably because you’re specifying a time zone name, but your MySQL installation hasn’t yet been configured for named time zones.
To fix this issue, be sure that your MySQL installation has been configured for named time zones.
Continue readingFix “lastval is not yet defined in this session” When Calling the LASTVAL() Function in PostgreSQL
If you’re getting an error that reads something like “lastval is not yet defined in this session” when calling the lastval()
function in PostgreSQL, it’s probably because nextval()
hasn’t yet been called in the current session.
If you want to avoid this error, only call the lastval()
function when you know that nextval()
has been called at least once in the current session.