% MATLAB 2022a and newer
% select_pg.m
psycopg2 = py.importlib.import_module('psycopg2');
conn = psycopg2.connect(host="localhost", port=int64(5432), ...
                        user="Al", password="SuperSecret",  ...
                        database="deliveries");
cursor = conn.cursor();

query = "select origin,sum(weight*cost_by_weight) from orders O, rates R" + ...
        "    where O.item = R.item group by origin order by origin;";
cursor.execute(query);
for row = cursor.fetchall()
    fprintf('%s  %7.2f\n', string(row{1}{1}), row{1}{2});
end

conn.close()
