Quick Intro to the event_scheduler System Variable in MySQL

In MySQL, the event_scheduler system variable is used to start and stop the Event Scheduler, as well as enable or disable it.

At runtime we can set the value to ON or OFF, and we can check the current value of the variable. We can also disable the Event Scheduler at server startup, but we can’t do this at runtime. However, we can still check the event_scheduler variable to see whether it’s enabled or disabled.

Continue reading

Fix “date/time field value out of range” in PostgreSQL

If you’re getting an error that reads ‘date/time field value out of range‘ in PostgreSQL while using a function such as date_add(), date_subtract(), or date_trunc(), it’s probably because the date value you’re passing to the function is an invalid date.

It’s possible that you’ve got the month and day in the wrong order.

To fix this issue, be sure that you pass a valid date. It may be that all you need to do is switch the day and the month around. Or it could be that you need to change your datestyle setting.

Continue reading

Fix Error “cannot take logarithm of zero” in PostgreSQL

If you’re getting an error that reads “ERROR: cannot take logarithm of zero” when using either the log() function or log10() function in PostgreSQL, it’s probably because you’re passing an argument of zero.

These functions require a value greater than zero. This is true even for the base argument of the log() function (the argument that specifies which base to use).

To fix this issue, be sure to pass a value greater than zero to these functions.

Continue reading

Understanding Composite Types in PostgreSQL

In PostgreSQL, a composite type is a kind of data type that consists of multiple data types. It consists of a list of field names and their respective data types.

We can use composite types to fit multiple fields into one column.

We can create our own custom composite types, and they can be used in many of the same scenarios that simple data types can be used.

Continue reading

Understanding PostgreSQL’s TRANSLATE() Function

PostgreSQL has a translate() function which replaces certain characters in a string with certain other characters.

We specify the characters in the string that we want to replace, as well as the characters that we want to replace them with. The function then performs the translation and returns the string with the replaced characters.

Continue reading