Understanding PostgreSQL’s pg_input_error_info() Function

PostgreSQL has a pg_input_error_info() function that allows us to see the error details that would be returned if we were to pass an invalid value for the specified data type.

Basically it tests whether the given string is valid input for the specified data type. If invalid, it returns the details of the error that would have been thrown. If valid, the result is null.

Continue reading

Understanding the sys.quote_identifier() Function in MySQL

In MySQL, we can use the sys.quote_identifier() function to quote a string to produce a result that can be used as an identifier in a SQL statement.

The string is returned enclosed by backticks (`), with each instance of a backtick doubled.

This function can be handy when a value to be used as an identifier is a reserved word or contains backtick characters.

Continue reading

Using the sys.format_statement() Function in MySQL to Truncate a SQL Statement

In MySQL, the sys.format_statement() system function reduces the length of a given string/SQL statement to the length stored in the statement_truncate_len configuration option.

This function can be handy for truncating potentially long SQL statements retrieved from Performance Schema tables into a more suitable length (64 characters by default).

Continue reading

Using the sys.format_path() Function to Dynamically Replace a Subpath with its Equivalent System Variable in MySQL

In MySQL, the sys.format_path() function is a stored function in the sys schema. It accepts a path name, and returns the modified path name after replacing subpaths that match the values of certain system variables.

So we can use the function to dynamically replace part or all of our path with a system variable that matches that path segment.

Continue reading