Olá Alexandre!

If the gid field is serial, you can not just omit it in the Rule - Insert Into 
statement?

CREATE OR REPLACE RULE "_INSERT" AS ON INSERT TO "PGHP".infra_portoes DO INSTEAD
INSERT INTO "PGHP"."infraestruturas_pontos" ("classe","nome","geom")
VALUES ('portoes',NEW."nome",NEW."geom");

That way, Postgresql follows the sequence smoothly. 

Or I did not realize the problem right?


Best regards,
Pedro Venâncio

 




>________________________________
> DE: Alexandre Neto <[email protected]>
>Para: QGIS User <[email protected]> 
>Enviadas: Sexta-feira, 28, Fevereiro 2014 16:03:37
>Assunto: [Qgis-user] How to set posgis default sequential value in a QGIS      
>"editable" view?
> 
>
>
>Hello all,
>
>
>I have posted this question in gis.stackexchage, does anyone have a solution 
>for it? 
>
>
>Thanks
>
>http://goo.gl/Bp6xZN
>
>
>Introduction
>In a QGIS project I have a VIEW, that I want to became editable (I'm trying to 
>replicate the versioning system used DB Manager with some tweeks). Therefore I 
>created a few rules to make is so (see below). I'm able to delete and update 
>the features without problems, but while inserting new features, I'm not being 
>able to use postgis default value (sequence) for gid (that in this case is not 
>a primary key) but has a NOT NULL constraint. So, if the user don't fill the 
>gid value, qgis is not be able to commit the changes, if it does... we neve 
>know where thing going to get wrong.
>The question
>Is there a way I can prepare my view or set qgis form to read the default 
>value?
>What I got
>-- The original tableCREATETABLE"PGHP".infraestruturas (gid serial,nome 
>character varying(40),classe character varying(40),geom 
>geometry(POINT,3763),"id_hist"serial 
>primarykey,"time_start"timestamp,"time_end"timestamp,"user_update"character 
>varying(40));-- Creating the viewCREATEORREPLACE VIEW"PGHP".infra_portoes 
>ASSELECT"gid","nome","geom"::Geometry(POINT,3763),"time_start","user_update"FROM"PGHP"."infraestruturas_pontos"WHERE"classe"='portoes'AND"time_end"ISNULL;--
> Make the view editableCREATEORREPLACE 
>RULE"_DELETE"ASONDELETETO"PGHP".infra_portoes DO INSTEAD 
>DELETEFROM"PGHP"."infraestruturas_pontos"WHEREgid =old.gid;CREATEORREPLACE 
>RULE"_INSERT"ASONINSERTTO"PGHP".infra_portoes DO INSTEAD 
>INSERTINTO"PGHP"."infraestruturas_pontos"("gid","classe","nome","geom")VALUES(NEW."gid",'portoes',NEW."nome",NEW."geom");CREATEORREPLACE
> RULE"_UPDATE"ASONUPDATETO"PGHP".infra_portoes DO INSTEAD
 
UPDATE"PGHP"."infraestruturas"SET"gid"=NEW."gid","classe"='portoes',"nome"=NEW."nome","geom"=NEW."geom"WHEREgid
 =NEW.gid;
>
>
>_______________________________________________
>Qgis-user mailing list
>[email protected]
>http://lists.osgeo.org/mailman/listinfo/qgis-user
>
>
_______________________________________________
Qgis-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to