4

I have a table in my PostGIS database. Its geometric objects I loaded in to my QGIS project as layer where I can edit them. In this layer (layer A) there are features with null values in some fields. I have another layer B with features containing specific values in these fields. I like to update the layer A with the values of the layer B by joining the segment_id.

With the tool "Join attributes by field value" from the toolbox I do not have the option to update an existing table. I can just save the output as a new table in my database.

Is there another way to update a table in the database with values from the attributes of a layer?

Bera
81.7k14 gold badges84 silver badges198 bronze badges
asked Aug 30, 2023 at 16:26
3
  • 1
    Are both 'layers' in PostgreSQL? If so, run an UPDATE through the DB Manager (or the DB client of your choice). If not, import the other first - you can do that through QGIS via drag'n'drop in the Browser panel. Commented Aug 30, 2023 at 17:15
  • @geozelot: what do you mean with drag'n'drop in the Browser panel? How to do that? Commented Aug 31, 2023 at 7:56
  • 1
    Drag and drop it: imgur.com/a/2yZYr3P Commented Aug 31, 2023 at 17:40

2 Answers 2

3

Import table B to PostgreSQL and:

UPDATE test.table_a AS a
SET 
 attr1 = b.attr2,
 attr2 = b.attr2,
 attr3 = b.attr3
FROM test.table_b as b
WHERE a.segment_id = b.segment_id

See: How to do an update + join in PostgreSQL?

enter image description here

answered Aug 30, 2023 at 17:15
0
2

You could join layer B with layer A on segment_id (layerproperties -> joins). Then you can open the attributetable and sort the field with missing values in table A. Then select all rows with missing values and use the fieldcalculator (start editing and open the combobox in the attributetable to select the field you want to update, then click on the E symbol) In the fieldcalculator choose fields and values and apply to selected rows.

answered Aug 31, 2023 at 8:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.