Geographic Information Systems Asked by thesunnyscientist on October 1, 2021
I am trying to copy the data from one database to another database. Both the source and target tables have 2 geometry columns — a polygon field and a point field. There are NOT NULL
constraints on both of these columns.
My ogr2ogr command looks like this
ogr2ogr -f "PostgreSQL" -append -update -sql "select polygon_geom, centre_geom, id, category from sourceschema.table1" PG:"dbname=db1 host=host1 port=5432 user=user password=password" PG:"dbname=db2 host=host2 port=5432 user=user password=password" -nln targetschema.table1
However I can’t get ogr to recognise the 2 geometry fields. The error i get is:
ERROR 1: ERROR: null value in column "geom" violates not-null constraint
How can I copy this data across my 2 databases properly? Even if I export just one geometry column, the NOT NULL constraint on the other column will still prevent me from inserting data. Or do I just lift the not null constraints for the time I’m transferring data across?
EDIT: The source and target tables are not exact copies of one another – the target table has more columns than the source.
Dont know much about ogr2ogr, but another options is to use FDW. With that, you can link data from one database directly to another. Then you can access these data as if they are in target database, without man in the middle software. This is much cleaner, because it uses plain sql, without extra hassle of ogr2ogr. It is more complicated for first setup (defining server, make foreign tables, etc) but then it is a breeze. There are some references:
Answered by DavidP on October 1, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP