[postgis-users] Inserting column from another table

Daniel GIL dangimar at gmail.com
Thu Apr 2 10:10:39 PDT 2015


No problem Bob, thank you for your answer.

On Thu, Apr 2, 2015 at 11:42 AM, Basques, Bob (CI-StPaul) <
bob.basques at ci.stpaul.mn.us> wrote:

>  All,
>
>
>
> Oh, geez, I just realized I wrote my answer using syntax from two
> different functions.
>
>
>
> It should have been more like what Dylan responded with . . . sorry to
> introduce confusion . . .
>
>
>
> Bobb
>
>
>
>
>
>
>
> *From:* postgis-users-bounces at lists.osgeo.org [mailto:
> postgis-users-bounces at lists.osgeo.org] *On Behalf Of *Daniel GIL
> *Sent:* Thursday, April 02, 2015 10:33 AM
> *To:* PostGIS Users Discussion
> *Subject:* Re: [postgis-users] Inserting column from another table
>
>
>
> Hi Dylan. It worked. I thought I tried that  yesterday but I probably did
> something wrong.
>
> Thank you very much for your answers,
>
> Regards,
>
> Daniel
>
>
>
> On Thu, Apr 2, 2015 at 11:00 AM, Dylan Adams <dylan.adams at gmail.com>
> wrote:
>
> 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
>
>
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
>
>
> _______________________________________________
> 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/524c0bd7/attachment.html>


More information about the postgis-users mailing list