Fix Error “time field value out of range” when using make_time() in PostgreSQL

If you’re getting an error that reads ‘time field value out of range‘ in PostgreSQL while using the make_time() function, it’s probably because one or more of the time parts you’re providing is out of the accepted range for that time part.

To fix this issue, be sure that each time part you provide is within the valid range for that time part.

Continue reading

How PostgreSQL’s CHARACTER_LENGTH() Function Works

In PostgreSQL, we can use the character_length() function to return the number of characters in a given string.

It accepts one argument; the string for which to return the length.

The character_length() function is a synonym for the char_length() function and so both do the same thing. We can also use the length() function to get the same result.

Continue reading

Fix Error “column … cannot be cast automatically to type …” in PostgreSQL

If you’re getting an error that reads something like ‘column “c1” cannot be cast automatically to type text[]‘ in PostgreSQL, it could be that you’re trying to change a column’s type to one where the existing type can’t be implicitly cast to.

To fix this issue, try explicitly casting the column to the desired data type.

Continue reading

Understanding STRING_TO_ARRAY() in PostgreSQL

In PostgreSQL, string_to_array() is a string function that allows us to create an array from a string. It splits the string based on the specified delimiter and returns a text array as a result.

If we specify a null delimiter, then each character becomes an element in the array. If the delimiter string is empty, then the whole string becomes a single element in the array.

We also have the option of turning a specific substring into null if required.

Continue reading