Bug report #13743

Pyqgis add field to PostGIS table fails

Added by Spencer Gardner over 1 year ago. Updated over 1 year ago.

Status:Open Start Date:11/02/2015
Priority:Normal Due date:
Assigned to:- % Done:

0%

Category:Python plugins and bindings
Target version:-
Platform: Pull Request or Patch supplied:No
Platform version: Affected version:2.10.1
Status info: Causes crash or corruption:No
Resolution: Tag:

Description

I'm trying to add a field to my PostGIS table using the following code:

--------------------------------------------------------
from PyQt4.QtCore import QVariant
from qgis.core import *

inLayer = iface.activeLayer()
provider = inLayer.dataProvider()

field = QgsField('test_field', QVariant.String)
inLayer.startEditing()
provider.addAttributes([field])
inLayer.updateFields()

inLayer.commitChanges()
--------------------------------------------------------

The commit fails and the PostGIS log shows an error:

2015-10-27T08:13:28 1 Erroneous query: ALTER TABLE "received"."env" ADD COLUMN "test_field" returned 7 [ERROR: syntax error at end of input
LINE 1: ALTER TABLE "received"."env" ADD COLUMN "test_field"

Seems the call to PostGIS fails to include the column type.

History

Updated by Giovanni Manghi over 1 year ago

  • Category set to Python plugins and bindings

Also available in: Atom