[postgis-users] Inserting column from another table

Dylan Adams dylan.adams at gmail.com
Thu Apr 2 08:00:01 PDT 2015


You'll need to use an UPDATE to accomplish what you're trying to do. It'll
probably look something like this

UPDATE Table1
SET geom = Table2.geom
FROM Table2
WHERE Table1.FabID = Table2.FabID;

There's more information in the Postgres' documentation about the UPDATE
statement:

http://www.postgresql.org/docs/9.4/interactive/sql-update.html

Regards,
dylan

On Thu, Apr 2, 2015 at 9:53 AM, Daniel GIL <dangimar at gmail.com> wrote:

> 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
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20150402/d1217d48/attachment.html>


More information about the postgis-users mailing list