Am 21.01.2019 um 22:41 schrieb Justin Pryzby:
> -- There are two columns here:
> pg.DB('ts').query('SELECT x.b, y.a AS b FROM (SELECT 1 AS b )x
> JOIN(SELECT 1 AS a)y ON true').getresult()> [(1, 1)]
>
> -- But here they're silently "collapsed" into one key:
> pg.DB('ts').query('SELECT x.b, y.a AS b FROM (SELECT 1 AS b )x
> JOIN(SELECT 2 AS a)y ON true').dictresult()> [{'b': 2}]
>
> ..which is scary to me since nobody knows what they're going to get,
> or that same value is being used for two different things instead of
> different values..
Well, the behavior is deterministic - you always get the column with the
highest index.
If you request a dict, then it's not reasonable to expect anything else.
Note that if you do a similar thing in Python, you don't get a warning
either:
dict([('b', 1), ('b', 2)]) = {'b': 2}
> If this is agreed to be a problem, maybe write warning to stderr in
> 5.0 and fail harder in 5.1+ ?
If anything, then there should be a Python warning, as it's not
considered good practice for a library or driver to print on stderr.
But as D'Arcy already commented, there should be only a warning when the
values differ. However, detecting this would cost too much performance.
So there are good reasons to leave things as they are.
Maybe we can just add a note to the docs for dictresult() that column
names are assumed to be unique.
-- Christoph
_______________________________________________
PyGreSQL mailing list
PyGreSQL@Vex.Net
https://mail.vex.net/mailman/listinfo/pygresql