I'm importing data into postgresql with shp2psql and pyhton's subprocess module.
command = 'shp2pgsql -s {SRID} -a -g geom -W "UTF-8" {SHP_path} {table_name} -I | ' \
'psql -h {hostname} -p {port} -d {db_name} -U {username}'\
.format(SRID=4326, SHP_path=shp_file, table_name=table_name,
hostname=hostname, port=port, db_name=db_name, username=username)
subprocess.call(command, shell=True)
The problem is that I cannot intercept import errors like
ERROR:
current transaction is aborted, commands ignored until end of transaction block
They are happening internally and don't stop the subprocess from execution so I have no means to control the result of execution. Is there any way to raise such errors in the main code?