[postgis-users] Inserting column from another table

Daniel GIL dangimar at gmail.com
Thu Apr 2 07:53:02 PDT 2015


Hello, I'm learning SQL/PostGIS and I need some help...

I have a table (Table1) with different fields (but no geometry field). This
table has already 35 rows of values.

I imported a second Table to the same database in pgAdmin using
pgShapeLoader. This second table has a geom field that I want to add to
Table1. The idea is to convert a non-spatial table to spatial

I created a geom field in Table 1 using AddColumn:


SELECT
AddGeometryColumn('UDE_spatial','public','table1','geom',4326,'POINT',2);


Now, I'm trying to add the values from geom field in Table 2 to geom field
in Table 1:

INSERT INTO Table1(geom)

SELECT geom

FROM Table2;


There are 35 rows to add and a common field 'FabID'. My surprise is that
instead of adding the values in the rows from 1 to 35, it starts in the row
number 36. It seems like you only could use INSERT INTO...SELECT when you
want to add fields  to a new table with no values added yet. I don't know
how to write the sentence in the way I need. I tried adding...WHERE fabid
BETWEEN 1 AND 35.


Well, that's probably a very simple question for most of you but I'm
getting crazy...lol


Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20150402/284dafc8/attachment.html>


More information about the postgis-users mailing list