<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello folks,</p>
    <p>I am importing multiple gpx files into a postgis database. The
      tables 'tracks' and 'track_points' are created / updated.<br>
    </p>
    <p>The column track_fid in in the track_points table should be a
      reference to the track feature id as documented in
      <a class="moz-txt-link-freetext" href="https://gdal.org/drivers/vector/gpx.html">https://gdal.org/drivers/vector/gpx.html</a>, however it is always
      zero.  <br>
    </p>
    <p>Is this a bug or am I missing something?</p>
    <h3>Details</h3>
    <p>I am creating an empty database, then create postgis extension
      with 'CREATE EXTENSION POSTGIS'</p>
    <p>I have two simple gpx files ( see attachments )<br>
    </p>
    <ul>
      <li>file1.gpx - containing 2 track segments - each with 3 track
        points<br>
      </li>
      <li>file2.gpx - containing 1 track segment  with 3 track points</li>
    </ul>
    <p>I am using commands</p>
    <p>ogr2ogr -f PostgreSQL -update -append "PG:dbname=testdb
      host=localhost user=postgres password=xx port=5432" file1.gpx<br>
    </p>
    <p>ogr2ogr -f PostgreSQL -update -append "PG:dbname=testdb
      host=localhost user=postgres password=xx port=5432" file2.gpx<br>
    </p>
    <p>Resulting data in 'tracks'</p>
    <p>
    </p>
    <table cellspacing="0" border="0">
      <colgroup width="68"></colgroup> <colgroup width="55"></colgroup>
      <colgroup width="56"></colgroup> <colgroup width="50"></colgroup>
      <colgroup width="56"></colgroup> <colgroup width="87"></colgroup>
      <colgroup width="86"></colgroup> <colgroup width="90"></colgroup>
      <colgroup width="87"></colgroup> <colgroup width="86"></colgroup>
      <colgroup width="90"></colgroup> <colgroup width="70"></colgroup>
      <colgroup width="46"></colgroup> <tbody>
        <tr>
          <td height="21" align="left">ogc_fid</td>
          <td align="left">name</td>
          <td align="left">cmt</td>
          <td align="left">desc</td>
          <td align="left">src</td>
          <td align="left">link1_href</td>
          <td align="left">link1_text</td>
          <td align="left">link1_type</td>
          <td align="left">link2_href</td>
          <td align="left">link2_text</td>
          <td align="left">link2_type</td>
          <td align="left">number</td>
          <td align="left">type</td>
          <td valign="top">wkb_geometry<br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">1</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td valign="top">...<br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">2</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td align="left">NULL</td>
          <td valign="top">...<br>
          </td>
        </tr>
      </tbody>
    </table>
    <p>
    </p>
    <p>
    </p>
    <table width="692" height="244" cellspacing="0" border="0">
      <colgroup width="68"></colgroup> <colgroup width="79"></colgroup>
      <colgroup width="110"></colgroup> <colgroup width="155"></colgroup>
      <colgroup width="35"></colgroup> <colgroup width="46"></colgroup>
      <tbody>
        <tr>
          <td height="21" align="left">ogc_fid</td>
          <td align="left">track_fid</td>
          <td align="left">track_seg_id</td>
          <td align="left">track_seg_point_id</td>
          <td align="left">ele</td>
          <td align="left">time</td>
          <td valign="top">.... other columns omitted ...<br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">1</td>
          <td align="right">0</td>
          <td align="right">0</td>
          <td align="right">0</td>
          <td align="right">1</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">2</td>
          <td align="right">0</td>
          <td align="right">0</td>
          <td align="right">1</td>
          <td align="right">1</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">3</td>
          <td align="right">0</td>
          <td align="right">0</td>
          <td align="right">2</td>
          <td align="right">1</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">4</td>
          <td align="right">0</td>
          <td align="right">1</td>
          <td align="right">0</td>
          <td align="right">2</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">5</td>
          <td align="right">0</td>
          <td align="right">1</td>
          <td align="right">1</td>
          <td align="right">2</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">6</td>
          <td align="right">0</td>
          <td align="right">1</td>
          <td align="right">2</td>
          <td align="right">2</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">7</td>
          <td align="right">0</td>
          <td align="right">0</td>
          <td align="right">0</td>
          <td align="right">3</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">8</td>
          <td align="right">0</td>
          <td align="right">0</td>
          <td align="right">1</td>
          <td align="right">3</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">9</td>
          <td align="right">0</td>
          <td align="right">0</td>
          <td align="right">2</td>
          <td align="right">3</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
      </tbody>
    </table>
    <p>Expected:</p>
    <p>
    </p>
    <table cellspacing="0" border="0">
      <colgroup width="68"></colgroup> <colgroup width="79"></colgroup>
      <colgroup width="110"></colgroup> <colgroup width="155"></colgroup>
      <colgroup width="35"></colgroup> <colgroup width="46"></colgroup>
      <tbody>
        <tr>
          <td height="21" align="left">ogc_fid</td>
          <td align="left">track_fid</td>
          <td align="left">track_seg_id</td>
          <td align="left">track_seg_point_id</td>
          <td align="left">ele</td>
          <td align="left">time</td>
          <td valign="top">.... other columns omitted ...<br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">1</td>
          <td align="right">1<br>
          </td>
          <td align="right">0</td>
          <td align="right">0</td>
          <td align="right">1</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">2</td>
          <td align="right">1<br>
          </td>
          <td align="right">0</td>
          <td align="right">1</td>
          <td align="right">1</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">3</td>
          <td align="right">1<br>
          </td>
          <td align="right">0</td>
          <td align="right">2</td>
          <td align="right">1</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">4</td>
          <td align="right">1<br>
          </td>
          <td align="right">1</td>
          <td align="right">0</td>
          <td align="right">2</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">5</td>
          <td align="right">1<br>
          </td>
          <td align="right">1</td>
          <td align="right">1</td>
          <td align="right">2</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">6</td>
          <td align="right">1<br>
          </td>
          <td align="right">1</td>
          <td align="right">2</td>
          <td align="right">2</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">7</td>
          <td align="right">2<br>
          </td>
          <td align="right">0</td>
          <td align="right">0</td>
          <td align="right">3</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">8</td>
          <td align="right">2<br>
          </td>
          <td align="right">0</td>
          <td align="right">1</td>
          <td align="right">3</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
        <tr>
          <td height="21" align="right">9</td>
          <td align="right">2<br>
          </td>
          <td align="right">0</td>
          <td align="right">2</td>
          <td align="right">3</td>
          <td align="left">NULL</td>
          <td valign="top"><br>
          </td>
        </tr>
      </tbody>
    </table>
    <p>I also tried to omit -update -append, but same result.<br>
    </p>
    <p>Versions:</p>
    <ul>
      <li>Postgres: "PostgreSQL 12.5 on x86_64-pc-linux-musl, compiled
        by gcc (Alpine 9.3.0) 9.3.0, 64-bit"<br>
      </li>
      <li>Postgis: "POSTGIS="3.0.3 0" [EXTENSION] PGSQL="120"
        GEOS="3.8.1-CAPI-1.13.3" PROJ="7.0.1" LIBXML="2.9.10"
        LIBJSON="0.14" LIBPROTOBUF="1.3.3" WAGYU="0.4.3 (Internal)""<br>
      </li>
      <li>Gdal: 3.2.0<br>
      </li>
    </ul>
  </body>
</html>