I am running

Command '['C:\\OSGeo4W\\bin\\ogr2ogr.exe', '-progress', '-skipfailures', '-overwrite', '-lco', 'UPLOAD_GEOM_FORMAT=wkt',
 '-t_srs', 'EPSG:28354', '-f', 'MSSQLSpatial', 'MSSQL:Server=xxx;Database=xxxGIS_Test;Trusted_Connect
ion=True', 'D:\\GIS_SourceData\\xxx\\HY_WATERBODY_STATE.tab', '-nln', 'DSE_HY_WATERBODY_STATE']'

But this is appending records to the table in MSSQL instead of overwriting the whole table?

Is there some switch to just tell it to update records/insert new ones or what should I do to get -overwrite to not append?

enter image description here

The _backup view is the original that was just backed up before running the command.

UPDATED EXAMPLE enter image description here

WITH DEBUG enter image description here Is there a way in OGR to delete the table or delete the records in the table before overwrite?

  • 1
    do you get the expected result if you include the -update flag? – SaultDon Mar 15 '19 at 1:45
  • 1
    Don't swap em, need both, and add both of these too -lco OVERWRITE=YES and -append – SaultDon Mar 15 '19 at 2:14
  • 1
    I don't know much about mssql tables, but for postgresql ones you can just use -append with --config OGR_TRUNCATE YES – SaultDon Mar 15 '19 at 4:14
  • 1
    if you're gonna try thE TRUNCATE config option. can replace both -overwrite and -update with just -append. also the -lco options wont have any effect because the layer already exists – SaultDon Mar 15 '19 at 5:17
  • 1
    Because the driver has its own overwrite option gdal.org/drv_mssqlspatial.html then I guess that it is made for purpose and the -overwrite option of ogr2ogr is not needed at all. Have you tried with just -lco OVERWRITE=YES? – user30184 Mar 15 '19 at 6:24

Unfortunately there seems to be an issue when OGR wasn't used to initially create the table in MSSQL. It maybe just for tables created by Pitney Bowes "Easyloader" and may not happen if the table was created by other systems.

So simply deleting/renaming the table before running the OGR2OGR command the first time, ensures that the data is just updated/replaced and not appended in subsequent calls.

Thanks to all the help here I found a lot of interesting switches that aren't clearly documented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.