Details
Description
CREATE TABLE user_location
(
user_name character varying(50) NOT NULL,
user_bbox geometry NOT NULL,
user_enter_ts timestamp without time zone DEFAULT now(),
user_location_id serial NOT NULL,
CONSTRAINT user_location_id PRIMARY KEY (user_location_id)
)
Using javascript to generate timestamp(ISO-8601 format) [SUCCESSFUL]:
//generated from user's mouse moves
var feature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.MultiPolygon(bounds.toGeometry()));
// Set feature attributes. user_bbox is generated from
var d = new Date();
feature.attributes =
;
// Add it to the layer.
map.layers[locLayerNum].addFeatures([feature]);
// Post.
map.layers[locLayerNum].commit();
Resultant POST body:
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" version="1.0.0" service="WFS"><wfs:Insert>
<feature:user_location xmlns:feature="https://www.djc2.org/schemas"><feature:user_bbox>
<gml:MultiPolygon xmlns:gml="http://www.opengis.net/gml"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing>
<gml:coordinates decimal="." cs="," ts=" ">-159.43359375,-17.05078125 42.36328125,-17.05078125 42.36328125
,50.44921875 -159.43359375,50.44921875 -159.43359375,-17.05078125</gml:coordinates></gml:LinearRing>
</gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon>
</feature:user_bbox><feature:user_name>test01</feature:user_name>
<feature:user_enter_ts>2009-03-18T15:32:47.024Z</feature:user_enter_ts></feature:user_location></wfs:Insert></wfs:Transaction>
---------------------------------------------------------------------------------------------------------------------------------------------------
Now we remove the javascript generated timestamp and allow postgres to generate the timestamp with the DEFAULT now() declaration in CREATE TABLE:
//feature attribute with timestamp removed.
feature.attributes =
;
Resultant POST body:
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" version="1.0.0" service="WFS"><wfs:Insert>
<feature:user_location xmlns:feature="https://www.djc2.org/schemas">
<feature:user_bbox><gml:MultiPolygon xmlns:gml="http://www.opengis.net/gml">
<gml:polygonMember><gml:Polygon><gml:outerBoundaryIs>
<gml:LinearRing><gml:coordinates decimal="." cs="," ts=" ">-273.1640625,-50.9765625 130.4296875,-50.9765625 130.4296875
,84.0234375 -273.1640625,84.0234375 -273.1640625,-50.9765625</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon>
</feature:user_bbox><feature:user_name>test01</feature:user_name></feature:user_location></wfs:Insert></wfs:Transaction>
Fails. No now() value inserted into user_enter_ts as a NULL value is inserted by postgis.
INSERT INTO "public"."user_location"
("user_name","user_bbox","user_enter_ts")
VALUES
('test01',setSRID('...'::geometry,4326),null)
Thanks.
Issue Links
- relates to
-
GEOT-2526
Recognize columns with default values, treat them accordingly
-
This appears to be related to GEOT-1806
Have a look there for a workaround.