In MySQL, the DEFAULT()
function returns the default value for a given column in the database.
If the column doesn’t have a default value, an error is returned.
Continue readingDatabase Management Systems
In MySQL, the DEFAULT()
function returns the default value for a given column in the database.
If the column doesn’t have a default value, an error is returned.
Continue readingIn MySQL, the data directory stores information managed by the MySQL server. Each subdirectory of the data directory is a database directory and corresponds to a database managed by the server.
If you ever need to find out where the data directory is located on your MySQL implementation, below are some options to try.
Continue readingIf you’ve been using MySQL for any decent amount of time, it’s likely you’ll be familiar with error 1055 that reads something like “Expression #N of SELECT list is not in GROUP BY clause and contains nonaggregated column…“, where #N
is the expression number of an expression/column in your SELECT
list.
This error can occur when we include a column in the SELECT
list, but we omit it from the GROUP BY
clause.
There are several ways we can go about resolving this issue. Below are six options for dealing with this issue.
Continue readingIn MySQL, we can include the AUTO_INCREMENT
attribute within a column definition in order to create an auto-incrementing column.
Generally, when we do this MySQL will automatically generate a value for us whenever we insert a new row into the table. I say “generally” because we can still explicitly insert our own value if that’s required.
Continue readingIf you’re getting error 1048 that reads something like “Column ‘ColumnName’ cannot be null” (where ColumnName is the name of a column you’re trying to insert data into), then it’s probably because you’re trying to insert a NULL
value into that column, but the column has a NOT NULL
constraint (which prevents NULL
values from being inserted).
We have a few options when it comes to fixing this issue. The most obvious is to ensure we provide a non-NULL
value for the column. Alternatively, if the column should be able to accept NULL
values, then we can remove the NOT NULL
constraint from the column. Another option is to use the IGNORE
keyword to ignore the error. And another way to deal with the error is to disable strict mode.
The following table contains a full list of the aggregate functions in MySQL.
Continue readingIn MySQL, we can use the IGNORE
clause in statements that change data in order to ignore certain errors that might occur had we not used it. When IGNORE
is used, such errors are downgraded to warnings.
For example, we can use IGNORE
in an INSERT
statement to ignore any errors we might normally get if we tried to insert a NULL
value into a NOT NULL
column. In such a case, MySQL won’t return an error. Instead, it will deal with the issue in another way, and provide us with a warning.
If we have strict mode enabled, we can use IGNORE
to force MySQL to act as though strict mode is disabled. However, IGNORE
can also be used to downgrade certain errors regardless of the strict mode setting.
Strict mode controls how MySQL handles invalid or missing values in statements that change data, such as in INSERT
and UPDATE
statements.
Strict mode (aka strict SQL mode) is in effect if either STRICT_ALL_TABLES
or STRICT_TRANS_TABLES
is enabled.
In MySQL 8.0, the default SQL mode includes STRICT_TRANS_TABLES
, which enables strict SQL mode for transactional storage engines, and when possible for nontransactional storage engines.
We can disable strict mode in our session by removing it from our @@sql_mode
variable. We can also disable strict mode at server startup, so that we don’t have to do it at runtime.
If you’re getting an error that reads “step size cannot equal zero” when creating a series with the generate_series()
function in PostgreSQL, it’s because you’re using a step size of 0
(i.e. zero).
The generate_series()
function doesn’t accept a zero step size.
To fix this issue, either use a non-zero step size, or remove the step size altogether (so that the default step is used).
Continue readingIn MySQL, the GROUPING()
function allows us to identity which rows have been generated by the WITH ROLLUP
modifier of the GROUP BY
clause.
By default, WITH ROLLUP
outputs NULL
as the value that represents all aggregate values. By this, I mean it doesn’t provide us with a nice easy to read label. It simply outputs NULL
. This makes it more difficult for us to distinguish between normal rows and super aggregate rows that were generated by WITH ROLLUP
.