0

Using python, I want to add a feature into a postgis layer that has a PK generated by a sequence.

layer (id [PK], field1, field2)

with edit(layer):
            fields = layer.pendingFields()
            new_feat = QgsFeature(fields)
            new_feat[1] = 'text1'
            new_feat[2] = 'text2'

            layer.addFeatures([new_feat])

But I get an error saying the value is too long for the type of the id attribute

Question: How can I assign the next value of the postgis sequence to the id?

var29
  • 51
  • 6

2 Answers2

0

try the following:

with edit(layer):
    fields = layer.pendingFields()
    new_feat = QgsFeature(fields)
    newFeat.setAttributes([NULL, 'text 1', 'text 2'])

    layer.addFeatures([new_feat])
firefly-orange
  • 2,521
  • 6
  • 23
0

This post gives the solution: How to create a QgsFeature with default attributes?

Can anyone mark this question has a duplicate?

var29
  • 51
  • 6