Am 24.08.2016 um 04:23 schrieb [email protected]:
A possibly unintentional backwards-incompability with pygresql-5+.

Assigning to an element of what used to be a list but is now a Row object,
for example:

  r[4] = None

results in:

  TypeError: 'Row' object does not support item assignment

Can support for item assignment be restored?

Or are the advantages of using a namedtuple
instead of a list too compelling?

The latter. A namedtuple is the most suitable and convenient type for a table row and used by most other database drivers in Python, so it has been changed in PyGres 5.0 with intent.

But even between tuple and list, tuple would be the more "Pythonically appropriate" choice for a row type (see e.g. http://nedbatchelder.com/blog/201608/lists_vs_tuples.html).

Having said this, you can restore the old Cursor type that returns lists instead of named tuples:

    class ListCursor(pgdb.Cursor):
        def row_factory(self, row):
            return row

    connection = pgdb.connect(database='unittest')
    connection.cursor_type = ListCursor
    cursor = connection.cursor()
    r = cursor.execute("select 1,2,3,'abc'").fetchone()
    r[2] = 7
    print(r)  # [1, 2, 7, 'abc']

See also the documentation for an example returning dicts instead:

http://www.pygresql.org/contents/pgdb/cursor.html#pgdb.Cursor.row_factory

-- Chris
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql

Reply via email to