Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mappedResultsQuery splits rows in 2 subsets with key null when there are functions in SELECT parameters #149

Open
pedropastor opened this issue Dec 8, 2020 · 3 comments

Comments

@pedropastor
Copy link

pedropastor commented Dec 8, 2020

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.

@isoos
Copy link
Collaborator

isoos commented Dec 8, 2020

@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.

@isoos
Copy link
Collaborator

isoos commented Dec 8, 2020

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.

@pedropastor
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants