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
docker-compose exec database psql teslamate teslamate < teslamate_merge_charges.sql
Then, call it in the psql
CLI with
CALL merge_drives(start_drive_id, end_drive_id);
CALL merge_charges(start_charge_id, end_charge_id);
merge_charges
is derived from a post by Dulanic, but taking cost into account.