ogr2ogr shp import to postgis and add column

1.2k Views Asked by At

I'm trying to import a shapefile into a non existing Postgis table. I'm using ogr2ogr with -sql option to select the fields from the shp that I would like to get imported however I would need a date field (that does not exists in my input shp) to be created in my output table. Is there any option within ogr2ogr for that ?

I've tried :

ogr2ogr -f "PostgreSQL" -a_srs "EPSG:4326" PG:"host=<db_host> user=<db_user> password=<db_password> dbname=<db_name>" -nlt MULTIPOLYGON -nln <table_name> -sql "SELECT <shp_field1> AS <pg_field1>,  <shp_field2> AS <pg_field2>,  current_date AS date FROM <shapeFile>" -overwrite <shapeFile>.shp

However I get an error 'Unrecognized field name current_date' which obviously does not exists in my input shapefile. Thanks for your help.

1

There are 1 best solutions below

1
user11681321 On

ok I get it to work by adding -dialect SQLite to by command line however it does not import the geometry anymore ...