Patch for issue 8920.

Fix to error with PostgreSQL and QGIS.
http://hub.qgis.org/issues/8920