Please note that the functions are only capable to merge a continuous range of drives/charges.
Make sure that all drives that shall be merged are terminated (how to terminate drives manually is described in the documentation.
Create the function by executing the file with e.g.
docker-compose exec database psql teslamate teslamate < teslamate_merge_drives.sql