Update multiple rows in a table from another table when condition exists

后端 未结 3 948
说谎
说谎 2021-02-13 17:58

I have two tables.

Table1 contains companies whose locations are georeferenced with lat/lng coordinates in a column called the_geom

3条回答
  •  后悔当初
    2021-02-13 18:34

    Assuming that by

    insert "the_geom" lat/lng values

    you actually mean to update existing rows in table2:

    UPDATE table2 t2
    SET    the_geom = t1.the_geom
    FROM   table1 t1
    WHERE  t2.address = t1.address
    AND    t2.the_geom IS DISTINCT FROM t1.the_geom; -- avoid empty updates
    

    Also assuming that the address column has UNIQUE values.
    Details about UPDATE in the excellent manual here.

提交回复
热议问题