This is an update for MySQL 8 Stored PSM to add the ONLY_FULL_GROUP_BY mode to the global SQL_MODE variable when it’s not set during a session. Here’s the code:
/* Drop procedure conditionally on whether it exists already. */
DROP PROCEDURE IF EXISTS set_full_group_by;
/* Reset delimter to allow semicolons to terminate statements. */
DELIMITER $$
/* Create a procedure to verify and set connection parameter. */
CREATE PROCEDURE set_full_group_by()
LANGUAGE SQL
NOT DETERMINISTIC
SQL SECURITY DEFINER
COMMENT 'Set connection parameter when not set.'
BEGIN
/* Check whether full group by is set in the connection and
if unset, set it in the scope of the connection. */
IF EXISTS
(SELECT TRUE
WHERE NOT REGEXP_LIKE(@@SESSION.SQL_MODE,'ONLY_FULL_GROUP_BY'))
THEN
SET @@GLOBAL.SQL_MODE := CONCAT(@@SESSION.sql_mode,',ONLY_FULL_GROUP_BY');
END IF;
END;
$$
/* Reset the default delimiter. */
DELIMITER ;
You can call the …
[Read more]