Re: [gdal-dev] Add timestamp field with value to table during ogr2ogr operation

2017-10-29 Thread Even Rouault
On dimanche 29 octobre 2017 09:58:06 CET Bo Victor Thomsen wrote:
> To the list -
> 
> I'm converting shapefiles to postgres tables using ogr2ogr. As usual
> with ogr2ogr, it works very well.
> 
> Now I want to automatically add an extra column "created" with the
> current timestamp during the ogr2ogr operation.
> 
> Something like this:
> 
> ogr2ogr .  -sql "SELECT *, CURRENT_TIMESTAMP AS created FROM
> point_data" 
> 
> Shapefile name is "point_data.shp" and CURRENT_TIMESTAMP is a SQL92
> standard function

OGR SQL is only a partial implementation of SQL92 :
http://gdal.org/ogr_sql.html

> 
> However, It doesn't work. Is there some way, I can add this timestamp
> value to the resulting table using a built-in function in ogr2ogr?

You may use the SQL SQLite dialect by adding -dialect SQLite
( http://gdal.org/ogr_sql_sqlite.html )
to your ogr2ogr command line, and that will do what you expect

Or almost, as I see that the column is recognized as a String column with 
values like 
'2017-10-29 10:26:43'. So you may need to do some SQL transformation on the PG 
database 
to properly type it.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

[gdal-dev] Add timestamp field with value to table during ogr2ogr operation

2017-10-29 Thread Bo Victor Thomsen

To the list -

I'm converting shapefiles to postgres tables using ogr2ogr. As usual 
with ogr2ogr, it works very well.


Now I want to automatically add an extra column "created" with the 
current timestamp during the ogr2ogr operation.


Something like this:

ogr2ogr .  -sql "SELECT *, CURRENT_TIMESTAMP AS created FROM 
point_data" 


Shapefile name is "point_data.shp" and CURRENT_TIMESTAMP is a SQL92 
standard function


However, It doesn't work. Is there some way, I can add this timestamp 
value to the resulting table using a built-in function in ogr2ogr?


(The above command works, if you replace "CURRENT_TIMESTAMP" with ex. 
"OGR_TYPE". Obviously It doesn't produce a timestamp after this edit ;-)


Kind regards
Bo Victor Thomsen




___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev