[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgis-users
Subject:    Re: [postgis-users] QGis 2.0 Copy/Paste from shapefile to Postgis issue if the primary key is a stri
From:       Denis Rouzaud <denis.rouzaud () gmail ! com>
Date:       2014-01-31 14:12:26
Message-ID: 52EBAF4A.8010601 () gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

QGIS prevent to overwrite the primary key field when it copies/pastes, 
this is why it leaves the field empty.
One way would be to add the constraint after the copy/paste if it's for 
a single shot.
Otherwise, just add a unique constraint on f1 and add a serial as 
primary key.

Cheers,

Denis

On 31. 01. 14 15:02, F T wrote:
> Hello
>
> We have a pb with copy/paste from a shapefile to postgis if the 
> primary key is a string.
> The primary key is left NULL and no commit is possible.
>
> To reproduce the pb :
>
> Create *table1 *with a string primary key
>
>     CREATE TABLE table1
>     (
>       f1 character varying(10) NOT NULL,
>       f2 character varying(10),
>       geom geometry,
>     *CONSTRAINT t1_pkey PRIMARY KEY (f1),*
>     CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 2),
>     CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) =
>     'POINT'::text),
>     CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) = 2154)
>     )
>
>
> *table2* is the same as table 1 but it has no primary key
>
>     CREATE TABLE table2
>     (
>       f1 character varying(10) NOT NULL,
>       f2 character varying(10),
>       geom geometry,
>       CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 2),
>       CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) =
>     'POINT'::text),
>       CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) = 2154)
>     )
>
>
> *shapes.shp* is a shapefile that contains the points I would like to 
> copy/paste in the Postgis tables
> (see attached zip file)
>
> 1) if I copy/paste the points from shapes.shp to table1, the key field 
> stays NULL and the commit is impossible.
> 2) if I copy/paste the points from shapes.shp to table2, everything is ok.
>
> Have you ever seen this bug?
>
> Thanks
>
> Fabrice
>
>
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users@lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users


[Attachment #5 (text/html)]

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi,<br>
    <br>
    QGIS prevent to overwrite the primary key field when it
    copies/pastes, this is why it leaves the field empty.<br>
    One way would be to add the constraint after the copy/paste if it's
    for a single shot.<br>
    Otherwise, just add a unique constraint on f1 and add a serial as
    primary key.<br>
    <br>
    Cheers,<br>
    <br>
    Denis<br>
    <br>
    <div class="moz-cite-prefix">On 31. 01. 14 15:02, F T wrote:<br>
    </div>
    <blockquote
cite="mid:CABmeFje6DT3OgEDnj9bEkotLehNxUqHjP=wvAkZhFahcUHefOg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>Hello<br>
                <br>
              </div>
              We have a pb with copy/paste from a shapefile to postgis
              if the primary key is a string.<br>
            </div>
            The primary key is left NULL and no commit is possible.<br>
            <br>
          </div>
          To reproduce the pb :<br>
          <br>
          Create <b>table1 </b>with a string primary key <br>
          <blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px
            solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><span
              style="font-family:courier new,monospace"><font>CREATE
                TABLE table1</font></span><br>
            <span style="font-family:courier new,monospace"><font>(</font></span><br>
            <span style="font-family:courier new,monospace"><font>&nbsp; f1
                character varying(10) NOT NULL,</font></span><br>
            <span style="font-family:courier new,monospace"><font>&nbsp; f2
                character varying(10),</font></span><br>
            <span style="font-family:courier new,monospace"><font>&nbsp; geom
                geometry,</font></span><br>
            <span style="font-family:courier new,monospace"><font>&nbsp; \
<b>CONSTRAINT  t1_pkey PRIMARY KEY (f1),</b></font></span><br>
            <span style="font-family:courier new,monospace"><font>&nbsp;
                CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = \
2),</font></span><br>  <span style="font-family:courier new,monospace"><font>&nbsp;
                CONSTRAINT enforce_geotype_geom CHECK
                (geometrytype(geom) = 'POINT'::text),</font></span><br>
            <span style="font-family:courier new,monospace"><font>&nbsp;
                CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) =
                2154)</font></span><br>
            <span style="font-family:courier new,monospace"><font>)</font></span><br>
            <span style="font-family:courier new,monospace"></span></blockquote>
          <span style="font-family:courier new,monospace"><br>
          </span><b>table2</b> is the same as table 1 but it has no
          primary key<br>
          <blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px
            solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><span
              style="font-family:courier new,monospace">CREATE TABLE
              table2</span><br>
            <span style="font-family:courier new,monospace">(</span><br>
            <span style="font-family:courier new,monospace">&nbsp; f1
              character varying(10) NOT NULL,</span><br>
            <span style="font-family:courier new,monospace">&nbsp; f2
              character varying(10),</span><br>
            <span style="font-family:courier new,monospace">&nbsp; geom
              geometry,</span><br>
            <span style="font-family:courier new,monospace">&nbsp; CONSTRAINT
              enforce_dims_geom CHECK (st_ndims(geom) = 2),</span><br>
            <span style="font-family:courier new,monospace">&nbsp; CONSTRAINT
              enforce_geotype_geom CHECK (geometrytype(geom) =
              'POINT'::text),</span><br>
            <span style="font-family:courier new,monospace">&nbsp; CONSTRAINT
              enforce_srid_geom CHECK (st_srid(geom) = 2154)</span><br>
            <span style="font-family:courier new,monospace">)</span><br>
            <span style="font-family:courier new,monospace"></span></blockquote>
          <br>
          <b>shapes.shp</b> is a shapefile that contains the points I
          would like to copy/paste in the Postgis tables<br>
          (see attached zip file)<br>
          <br>
          1) if I copy/paste the points from shapes.shp to table1, the
          key field stays NULL and the commit is impossible.<br>
          2) if I copy/paste the points from shapes.shp to table2,
          everything is ok.<br>
          <br>
        </div>
        <div>Have you ever seen this bug?<br>
          <br>
        </div>
        <div>Thanks<br>
          <br>
        </div>
        <div>Fabrice<br>
        </div>
        <div><br>
          <br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
postgis-users mailing list
<a class="moz-txt-link-abbreviated" \
href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a> <a \
class="moz-txt-link-freetext" \
href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a></pre>
  </blockquote>
    <br>
  </body>
</html>



_______________________________________________
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic