<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=iso-8859-1"><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:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
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;}
pre
        {mso-style-priority:99;
        mso-style-link:"Préformaté HTML Car";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.hps
        {mso-style-name:hps;}
span.ita-kd-inputtools-div
        {mso-style-name:ita-kd-inputtools-div;}
span.shorttext
        {mso-style-name:short_text;}
span.PrformatHTMLCar
        {mso-style-name:"Préformaté HTML Car";
        mso-style-priority:99;
        mso-style-link:"Préformaté HTML";
        font-family:Consolas;
        color:black;}
span.EmailStyle22
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
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 bgcolor=white lang=FR link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hello,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>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)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hugues.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></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'> postgis-users-bounces@lists.osgeo.org [mailto:postgis-users-bounces@lists.osgeo.org] <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<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hi,<br>I'm a postgis/postgres newbie and I <span class=hps><span lang=EN>I would like to</span></span><span lang=EN> <span class=hps>get some help</span> <span class=hps>on the topics</span> <span class=hps>that</span> <span class=hps>I'm going to</span> <span class=hps>describe.</span><br><br></span><o:p></o:p></p><div id=gt-res-content><div><p class=MsoNormal><span class=hps><span lang=EN>I have</span></span><span lang=EN> <span class=hps>imported into the database</span> <span class=hps>the shapefile</span> <span class=hps>"survey" of points</span> <span class=hps>(</span>trees). <span class=hps>The</span> <span class=hps>spatial</span> <span class=hps>table "</span>survey" <span class=hps>contains</span> <span class=hps>five</span> <span class=hps>columns</span>:<br><span class=hps>-</span> <span class=hps>"</span>Gid" <span class=hps>(</span>created <span class=hps>during import and</span> <span class=hps>primary key</span>, integer)<br><span class=hps>-</span> <span class=hps>"</span>Id"<br><span class=hps>-</span> <span class=hps>"Code</span>"<br><span class=hps>-</span> <span class=hps>"</span>Old number"<br><span class=hps>-</span> <span class=hps>"</span>Geom" <span class=hps>(</span>it <span class=hps>also</span> <span class=hps>created</span> <span class=hps>during import</span>).<br><br><span class=hps>The database includes</span> <span class=hps>several tables</span> <span class=hps>("Species</span>", <span class=hps>"</span>Defects", <span class=hps>"</span>Disease" <span class=hps>and</span> <span class=hps>others</span>) <span class=hps>related</span> <span class=hps>to the main table</span> <span class=hps>"</span>VTA".<br><span class=hps>Now I would like</span> <span class=hps>to know why</span>, <span class=hps>unlike what happened</span> <span class=hps>to</span> <span class=hps>the other</span> <span class=hps>tables,</span> <span class=hps>I can not connect</span> <span class=hps>with</span> <span class=hps>"</span>ADD <span class=hps>CONSTRAINT</span>" <span class=hps>column</span> <span class=hps>"</span>code" <span class=hps>(integer</span>, not null, <span class=hps>unique)</span> <span class=hps>of the table "</span>VTA" <span class=hps>to the corresponding</span> <span class=hps>column</span> <span class=hps>"</span>code" <span class=hps>(also</span> <span class=hps>integer</span>, not null) <span class=hps>the</span> <span class=hps>spatial</span> <span class=hps>table "</span>survey".<br><br><span class=hps>Another question</span>: <span class=hps>when I'm</span> <span class=hps>editing a</span> <span class=hps>field</span> <span class=hps>(</span>for <span class=hps>example</span> <span class=hps>"</span>species name" <span class=hps>in the column "</span>species" of table <span class=hps>"</span>VTA", <span class=hps>related</span> <span class=hps>to the table</span> <span class=hps>"Species</span>", <span class=hps>would that</span> <span class=hps>"species</span> <span class=hps>name"</span> <span class=hps>could</span> <span class=hps>be</span> <span class=hps>completed</span> <span class=hps>on the basis</span> <span class=hps>of the records</span> <span class=hps>in the table</span> <span class=hps>"Species</span>".</span> How can I do this?<br><span class=hps><span lang=EN>Thanks in advance.</span></span><span lang=EN><br><br><span class=hps>Alessio</span><br><br><br></span><o:p></o:p></p></div></div><p class=MsoNormal><br><br><o:p></o:p></p><pre><o:p> </o:p></pre></div></body></html>