Re:How I Reduced My DB Server Load by 80%
by stuartaxelowen on Tuesday October 10, 2017 @05:57AM
(#15440595)
If you're using python, you can use named tuples for everything. It's really nice! Check out the psycopg2 namedtuple connection.
[ Parent
| on HN ]
I just glanced at this, and maybe I don't understand, but it sounds like psycopg2 namedtuples only work on one table at a time; is this right?
Re:How I Reduced My DB Server Load by 80%
by stuartaxelowen on Tuesday October 10, 2017 @09:21PM
(#15446627)
The namedtuple is just a datastructure interface with psycopg2. For instance, you could write an arbitrary query "SELECT left.x AS cats, right.created_at FROM left JOIN right ON etc" and you'd get namedtuples with attrs `cats` and `created_at`. Similarly, you can insert namedtuples just like rows, since they are iterables, or as namedparameters with the nt._asdict() method. It's great!