Simplified structure regardless can look something like:
WPDB ->
monkey patched mySQL functions
-> parser / regex/ variable extraction
-> parsed MySQL representation (class or struct)
-> convert to Postgres representation
-> toSQL() method
-> execute against postgres database
<-- post process postgres output
<-- return data to WPDB
Investigate the same approach as the WordPress SQLite implemention https://github.com/phpmyadmin/sql-parser
https://wordpress.org/plugins/sqlite-database-integration/
Simplified structure regardless can look something like:
WPDB -> monkey patched mySQL functions -> parser / regex/ variable extraction -> parsed MySQL representation (class or struct) -> convert to Postgres representation -> toSQL() method -> execute against postgres database <-- post process postgres output <-- return data to WPDB