<div dir="ltr"><div>For the second part, <br></div>it depends hugely on how you edit the field.<br>Are you editing with psql, pgadmin, qgis, ...<br>Cheers,<br>Rémi-C<br></div><div class="gmail_extra"><br><div class="gmail_quote">2014-12-07 10:39 GMT+01:00 Hugues François <span dir="ltr"><<a href="mailto:hugues.francois@irstea.fr" target="_blank">hugues.francois@irstea.fr</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="white" link="blue" vlink="purple" lang="FR"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hello,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">I’m not sure to understand well your problems but it seems you have sql questions rather than postgis ones… For the first one, I don’t really understand what you are looking for but I think what you want to add is constraint called foreign key (you will find useful information in the postgres documentation). For your second questions, you may achieve that using a trigger function but you have to be aware that it will not work if you have a not null or a primary key constraint (except if you have a serial type, a sequence, or any other rule in your trigger function to fill this column automatically)<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">Hugues.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"><u></u> <u></u></span></p><div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm"><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">De :</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext"> <a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">postgis-users-bounces@lists.osgeo.org</a> [mailto:<a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">postgis-users-bounces@lists.osgeo.org</a>] <b>De la part de</b> Alessio Degioannini<br><b>Envoyé :</b> samedi 6 décembre 2014 13:32<br><b>À :</b> postgis-users<br><b>Objet :</b> [postgis-users] Help CONSTRAINTS and others questions<u></u><u></u></span></p></div></div><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Hi,<br>I'm a postgis/postgres newbie and I <span><span lang="EN">I would like to</span></span><span lang="EN"> <span>get some help</span> <span>on the topics</span> <span>that</span> <span>I'm going to</span> <span>describe.</span><br><br></span><u></u><u></u></p><div><div><p class="MsoNormal"><span><span lang="EN">I have</span></span><span lang="EN"> <span>imported into the database</span> <span>the shapefile</span> <span>"survey" of points</span> <span>(</span>trees). <span>The</span> <span>spatial</span> <span>table "</span>survey" <span>contains</span> <span>five</span> <span>columns</span>:<br><span>-</span> <span>"</span>Gid" <span>(</span>created <span>during import and</span> <span>primary key</span>, integer)<br><span>-</span> <span>"</span>Id"<br><span>-</span> <span>"Code</span>"<br><span>-</span> <span>"</span>Old number"<br><span>-</span> <span>"</span>Geom" <span>(</span>it <span>also</span> <span>created</span> <span>during import</span>).<br><br><span>The database includes</span> <span>several tables</span> <span>("Species</span>", <span>"</span>Defects", <span>"</span>Disease" <span>and</span> <span>others</span>) <span>related</span> <span>to the main table</span> <span>"</span>VTA".<br><span>Now I would like</span> <span>to know why</span>, <span>unlike what happened</span> <span>to</span> <span>the other</span> <span>tables,</span> <span>I can not connect</span> <span>with</span> <span>"</span>ADD <span>CONSTRAINT</span>" <span>column</span> <span>"</span>code" <span>(integer</span>, not null, <span>unique)</span> <span>of the table "</span>VTA" <span>to the corresponding</span> <span>column</span> <span>"</span>code" <span>(also</span> <span>integer</span>, not null) <span>the</span> <span>spatial</span> <span>table "</span>survey".<br><br><span>Another question</span>: <span>when I'm</span> <span>editing a</span> <span>field</span> <span>(</span>for <span>example</span> <span>"</span>species name" <span>in the column "</span>species" of table <span>"</span>VTA", <span>related</span> <span>to the table</span> <span>"Species</span>", <span>would that</span> <span>"species</span> <span>name"</span> <span>could</span> <span>be</span> <span>completed</span> <span>on the basis</span> <span>of the records</span> <span>in the table</span> <span>"Species</span>".</span> How can I do this?<br><span><span lang="EN">Thanks in advance.</span></span><span lang="EN"><br><br><span>Alessio</span><br><br><br></span><u></u><u></u></p></div></div><p class="MsoNormal"><br><br><u></u><u></u></p><pre><u></u> <u></u></pre></div></div></div></div><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><br></blockquote></div><br></div>