Author: cito
Date: Mon Feb 1 04:47:39 2016
New Revision: 811
Log:
Mention get_as_dict() in the tutorial
Modified:
trunk/docs/contents/tutorial.rst
Modified: trunk/docs/contents/tutorial.rst
==============================================================================
--- trunk/docs/contents/tutorial.rst Mon Feb 1 04:34:47 2016 (r810)
+++ trunk/docs/contents/tutorial.rst Mon Feb 1 04:47:39 2016 (r811)
@@ -66,9 +66,9 @@
>>> banana = db.insert('fruits', name='banana')
Or, you can add a whole bunch of fruits at the same time using the
-:meth:`DB.inserttable` method. Note that this method uses the COPY command
-of PostgreSQL to insert all data in one operation, which is faster than
-sending many INSERT commands::
+:meth:`Connection.inserttable` method. Note that this method uses the COPY
+command of PostgreSQL to insert all data in one batch operation, which is much
+faster than sending many individual INSERT commands::
>>> more_fruits = 'cherimaya durian eggfruit fig grapefruit'.split()
>>> data = list(enumerate(more_fruits, start=3))
@@ -107,6 +107,18 @@
>>> rows[3].name
'durian'
+Using the method :meth:`DB.get_as_dict`, you can easily import the whole table
+into a Python dictionary mapping the primary key *id* to the *name*::
+
+ >>> db.get_as_dict('fruits', scalar=True)
+ OrderedDict([(1, 'apple'),
+ (2, 'banana'),
+ (3, 'cherimaya'),
+ (4, 'durian'),
+ (5, 'eggfruit'),
+ (6, 'fig'),
+ (7, 'grapefruit')])
+
To change a single row in the database, you can use the :meth:`DB.update`
method. For instance, if you want to capitalize the name 'banana'::
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql