A hint to get you started . .

INSERT INTO  <tablename>  VALUES (SELECT <something> FROM . . . . )

Bobb



From: [email protected] 
[mailto:[email protected]] On Behalf Of Daniel GIL
Sent: Thursday, April 02, 2015 9:53 AM
To: [email protected]
Subject: [postgis-users] Inserting column from another table

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
_______________________________________________
postgis-users mailing list
[email protected]
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

Reply via email to