<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:"Comic Sans MS";
panose-1:3 15 7 2 3 3 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Comic Sans MS";
color:windowtext;
font-weight:normal;
font-style:normal;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Comic Sans MS"">All,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Comic Sans MS""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Comic Sans MS"">Oh, geez, I just realized I wrote my answer using syntax from two different functions.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Comic Sans MS""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Comic Sans MS"">It should have been more like what Dylan responded with . . . sorry to introduce confusion . . .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Comic Sans MS""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Comic Sans MS"">Bobb<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Comic Sans MS""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Comic Sans MS""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Comic Sans MS""><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> postgis-users-bounces@lists.osgeo.org [mailto:postgis-users-bounces@lists.osgeo.org]
<b>On Behalf Of </b>Daniel GIL<br>
<b>Sent:</b> Thursday, April 02, 2015 10:33 AM<br>
<b>To:</b> PostGIS Users Discussion<br>
<b>Subject:</b> Re: [postgis-users] Inserting column from another table<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:.5in">
Hi Dylan. It worked. I thought I tried that yesterday but I probably did something wrong.<o:p></o:p></p>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:.5in">
Thank you very much for your answers,<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-left:.5in">Regards,<br>
<br>
Daniel<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in">On Thu, Apr 2, 2015 at 11:00 AM, Dylan Adams <<a href="mailto:dylan.adams@gmail.com" target="_blank">dylan.adams@gmail.com</a>> wrote:<o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in">You'll need to use an UPDATE to accomplish what you're trying to do. It'll probably look something like this<o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">UPDATE Table1<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">SET geom = Table2.geom<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">FROM Table2<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">WHERE Table1.FabID = Table2.FabID;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">There's more information in the Postgres' documentation about the UPDATE statement:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><a href="http://www.postgresql.org/docs/9.4/interactive/sql-update.html" target="_blank">http://www.postgresql.org/docs/9.4/interactive/sql-update.html</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Regards,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">dylan<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">On Thu, Apr 2, 2015 at 9:53 AM, Daniel GIL <<a href="mailto:dangimar@gmail.com" target="_blank">dangimar@gmail.com</a>> wrote:<o:p></o:p></p>
</div>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Hello, I'm learning SQL/PostGIS and I need some help...<o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in"><br>
I have a table (Table1) with different fields (but no geometry field). This table has already 35 rows of values.<br>
<br>
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<br>
<br>
I created a geom field in Table 1 using AddColumn:<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in;text-align:justify">
<o:p> </o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in"><span lang="CA" style="font-size:10.0pt;color:#0070C0">SELECT AddGeometryColumn('UDE_spatial','public','table1','geom',4326,'POINT',2);</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in;text-align:justify">
<o:p> </o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in;text-align:justify">
Now, I'm trying to add the values from geom field in Table 2 to geom field in Table 1:<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in;text-align:justify">
<span lang="CA" style="font-size:10.0pt;color:#0070C0">INSERT INTO Table1(geom)</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in;text-align:justify">
<span lang="CA" style="font-size:10.0pt;color:#0070C0">SELECT geom</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in;text-align:justify">
<span lang="CA" style="font-size:10.0pt;color:#0070C0">FROM Table2;</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in;text-align:justify">
<o:p> </o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in;text-align:justify">
<span lang="CA" style="font-size:10.0pt;color:black">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.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in;text-align:justify">
<o:p> </o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in;text-align:justify">
<span lang="CA" style="font-size:10.0pt;color:black">Well, that's probably a very simple question for most of you but I'm getting crazy...lol</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-left:.5in;text-align:justify">
<o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span lang="CA" style="font-size:10.0pt;color:black">Thanks</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
</div>
<p class="MsoNormal" style="margin-left:.5in">_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<p class="MsoNormal" style="margin-left:.5in"><br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
</div>
</body>
</html>