mappedResultsQuery splits rows in 2 subsets with key null when there are functions in SELECT parameters
This query: SELECT index, mac::text, imei, backend, status, lockstatus, powerstatus, id, chargestatus, lastping::timestamptz, public.ST_AsText(lastpos) AS lastpos FROM iotdevices WHERE backend = "backend01"
Instead of returning this: {iotdevices: {index: 5, mac: e2:40:8b:ff:fe:48:02:63, imei: 867584031544559, backend: back01, status: OK, lockstatus: 1, powerstatus: 45, id: 010115, chargestatus: false, lastping: null, lastpos: null}}
It is incorrectly returning this, and I am not finding a way to retrieve the data from it properly: {iotdevices: {index: 5, imei: 867584031544559, backend: back01, status: OK, lockstatus: 1, powerstatus: 45, id: 010115, chargestatus: false, lastping: null}, null: {mac: e2:40:8b:ff:fe:48:02:63, lastpos: null}}
I guess there is some issue behind mapped query, and the execution (it may treat the query as 2 separate ones). When tested directly in DB works fine.
@pedropastor: Would you be able/willing to debug this a bit further with the postgres library? OID resolution happens here: https://github.com/stablekernel/postgresql-dart/blob/master/lib/src/connection.dart#L356-L398
It is likely that ::type casts change the oid for these fields and the SELECT relname FROM pg_class WHERE relkind='r' AND oid IN ($unresolvedIDString) ORDER BY oid ASC is not able to get any reasonable result for it.
As a workaround, you could use the regular query method, and when processing the row, calling toColumnMap, which doesn't use the table names, only the column names.
The workaround works, the regular query method returns things properly in one row.
I compromise to check the OID resolution, but we are now in a very tight schedule for delivering projects so I cannot promise anything about timing.
Thanks for your work and support.