I have been through many related questions and links but I am still confused as to how/if this is achievable. So, I have defined tables in my postgis database and I would like my ogr2ogr commnand to append to these existing tables rather than create its own - using GML files that I have.

I have tried using -nln and -sql but I had no success. The -nln option seems useful when importing a shapefile which usually contains one type of geometry thus needing to specify one table only. But what happens when need to specify 11 tables?

Finally, I found some links to use python with ogr library. I have not found good documentation with examples though...

Any suggestions?

1 Answer 1


From what I understood you want to append or update your postgis tables using a gml file

ogr2ogr provides such functionality using the --update flag like this:

ogr2ogr -update -f "PostgreSQL" PG:"host=myhost user=myloginname dbname=mydbname password=mypassword" 
myfile.GML  -nln <myschema>.<mytable>

you can also try the -append flag.

Now if you are on unix you can bash you way through multiple files with few lines of script:

for f in $(ls *.gml); do
    ogr2ogr -update -f "PostgreSQL" PG:"<pg-details-here>" "$f" -nln <myschema>.`basename $f .gml`;

in windows machines you can use instead of an bash interpreter, the MSYS program, which is installed with OSGeo4W utility.

  • Thanks for replying. My problem is that at the end of the command I want to be able to do something like <myschema>.<mytable1> <myschema>.<mytable2> <myschema>.<mytable3> <myschema>.<mytable4> ... because the GML contains geometries that need to be imported to different tables within the same schema. I will try the update command with the -nln and let you know!
    – Antony
    Commented Jul 12, 2013 at 15:33
  • can you post the ogrinfo output of your file?
    – nickves
    Commented Jul 12, 2013 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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