Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#6328 closed defect (fixed)

ogr2ogr -skip doesn't rollback transaction after failure

Reported by: Even Rouault Owned by: Even Rouault
Priority: normal Milestone: 2.0.2
Component: Utilities Version: unspecified
Severity: normal Keywords: ogr2ogr
Cc:

Description

The problem appears in the following layer.  The transaction is still in an
unusable state and hence the next statement also fails (ERROR 1: ERROR: current
transaction is aborted, commands ignored until end of transaction block).   In
my case with NAS data - ie. ia source with multiple layers - the retrieval of
the columns of a preexisting table fails.

This also shows the problem:

set -x
ogrinfo pg: -sql "drop table if exists test1; create table test1(id varchar unique, foo varchar); SELECT AddGeometryColumn('test1','dummy',-1,'POINT',2);"
ogrinfo pg: -sql "drop table if exists test2; create table test2(id varchar unique, foo varchar); SELECT AddGeometryColumn('test2','dummy',-1,'POINT',2);"
[ -d test ] || mkdir test
printf "id,foo\n1,1\n" >test/test1.csv
printf "id,foo\n1,1\n" >test/test2.csv
ogr2ogr -update -append pg: test
printf "id,foo\n1,1\n" >test/test1.csv
printf "id,foo\n2,2\n" >test/test2.csv
ogr2ogr -update -append pg: test -skip

ogrinfo pg: test1 test2

Gives:

+ ogrinfo pg: -sql 'drop table if exists test1; create table test1(id varchar unique, foo varchar); SELECT AddGeometryColumn('\''test1'\'','\''dummy'\'',-1,'\''POINT'\'',2);'
INFO: Open of `pg:'
      using driver `PostgreSQL' successful.

Layer name: sql_statement
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
addgeometrycolumn: String (0.0)
OGRFeature(sql_statement):1
  addgeometrycolumn (String) = public.test1.dummy SRID:-1 TYPE:POINT DIMS:2 

+ ogrinfo pg:' -sql 'drop table if exists test2; create table test2(id varchar unique, foo varchar); SELECT AddGeometryColumn('\''test2'\'','\''dummy'\'',-1,'\''POINT'\'',2);'
INFO: Open of `pg:'
      using driver `PostgreSQL' successful.

Layer name: sql_statement
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
addgeometrycolumn: String (0.0)
OGRFeature(sql_statement):1
  addgeometrycolumn (String) = public.test2.dummy SRID:-1 TYPE:POINT DIMS:2 

+ '[' -d test ']'
+ printf 'id,foo\n1,1\n'
+ printf 'id,foo\n1,1\n'
+ ogr2ogr -update -append pg: test
+ printf 'id,foo\n1,1\n'
+ printf 'id,foo\n2,2\n'
+ ogr2ogr -update -append pg: test -skip
ERROR 1: ERROR:  duplicate key value violates unique constraint "test1_id_key"

ERROR 1: INSERT command for new feature failed.
ERROR:  duplicate key value violates unique constraint "test1_id_key"

Command: INSERT INTO "test1" ("id", "foo") VALUES ('1', '1')
ERROR 1: ERROR:  current transaction is aborted, commands ignored until end of transaction block

ERROR 1: ERROR:  current transaction is aborted, commands ignored until end of transaction block

ERROR 1: ERROR:  current transaction is aborted, commands ignored until end of transaction block

ERROR 1: ERROR:  current transaction is aborted, commands ignored until end of transaction block

+ ogrinfo 'pg:' test1 test2
INFO: Open of `pg:'
      using driver `PostgreSQL' successful.

Layer name: test1
Geometry: Point
Feature Count: 1
Layer SRS WKT:
(unknown)
Geometry Column = dummy
id: String (0.0)
foo: String (0.0)
OGRFeature(test1):0
  id (String) = 1
  foo (String) = 1


Layer name: test2
Geometry: Point
Feature Count: 2
Layer SRS WKT:
(unknown)
Geometry Column = dummy
id: String (0.0)
foo: String (0.0)
OGRFeature(test2):0
  id (String) = 1
  foo (String) = 1

OGRFeature(test2):1
  id (String) = (null)
  foo (String) = (null)

The last row is from 'INSERT INTO "test2" DEFAULT VALUES' - which is used
because the retrieval of the columns of "test2" failed.

Change History (3)

comment:1 by Even Rouault, 8 years ago

Milestone: 2.0.2
Resolution: fixed
Status: newclosed

It seems to only affect dataset transactions (added in GDAL 2.0): trunk r33111, branches/2.0 r33112 "ogr2ogr -skip: rollback dataset transaction in case of failure (#6328)"

For the sake of completness, although it doesn't seem to cause problems in practice: branches/1.11 r33113 "ogr2ogr -skip: rollback transaction in case of failure (#6328)"

comment:2 by Jukka Rahkonen, 8 years ago

Do you mean -skipfailures or is there another and undocumented option called -skip?

in reply to:  2 comment:3 by Even Rouault, 8 years ago

Replying to jratike80:

Do you mean -skipfailures or is there another and undocumented option called -skip?

The official names is -skipfailures, but -skip or -skipanything will work too in practice

Note: See TracTickets for help on using tickets.