How to Disable Strict Mode in MySQL

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.

Continue reading

Fix “ERROR:  step size cannot equal zero” When Creating a PostgreSQL Series

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 reading

MySQL GROUPING() Function Explained

In 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.

Continue reading

How to Remove a SQL Mode from sql_mode in MySQL

MySQL can operate in different SQL modes. These can be set at server startup or at runtime.

DBAs can set the global SQL mode to match site server operating requirements, and each application can set its session SQL mode to its own requirements. Users can also set their own SQL mode at the session level via the @@sql_mode system variable.

By default, the sql_mode system variable contains a list of SQL modes that are applied.

As a user, we can modify our sql_mode system variable as required at runtime. This article demonstrates how we can remove a SQL mode from our sql_mode system variable.

Continue reading

How to Remove NOT NULL from a Column in MySQL

NOT NULL constraints are an important tool for maintaining data integrity in SQL databases. However, we may occasionally find that a NOT NULL constraint gets in the way of a legitimate operation that we want to perform, and it prevents us from entering data. In such cases, we may need to remove the NOT NULL constraint in order to proceed.

To remove a NOT NULL constraint in MySQL, we use the ALTER TABLE statement to redefine the relevant column without the NOT NULL constraint.

Continue reading

MySQL ANY_VALUE() Function Explained

In MySQL, ANY_VALUE() is an aggregate function that allows us to include nonaggregated columns in the SELECT list when using the GROUP BY clause.

The ANY_VALUE() function is commonly used to resolve issues that arise when a query includes columns that are not part of the GROUP BY clause or aggregate functions. It can be useful in scenarios where we want to include descriptive columns in a grouped result set without affecting the grouping behaviour.

Continue reading

Fix “LIMIT is only supported in combination with either BYSCORE or BYLEX” in Redis

If you’re getting an error that reads “LIMIT is only supported in combination with either BYSCORE or BYLEX” it’s probably because you’re trying to use the LIMIT clause without using the BYSCORE or BYLEX arguments.

This can happen when using the VRANGE command without either of the BYSCORE or BYLEX arguments.

To fix this issue, use either the BYSCORE or BYLEX argument when using the command. This obviously means that we need to adjust our query so that it’s querying by score or lexicographically.

Continue reading