[gdal-dev] CartoDB driver fail because drop sequence sentence fails

Even Rouault even.rouault at mines-paris.org
Thu Mar 6 11:05:21 PST 2014


Le jeudi 06 mars 2014 18:45:50, Jorge Arevalo a écrit :
> Hello,
> 
> I'm trying to create a new table in CartoDB using the GDAL CartoDB
> driver and Python bindings. I'm getting a HTTP 400 error.
> 
> This is the source code:
> 
> from osgeo import ogr
> from osgeo import gdal
> 
> gdal.SetConfigOption("CARTODB_API_KEY", MY_API_KEY)
> drv = ogr.GetDriverByName("CartoDB")
> cartodb_ds = drv.Open('cartodb:%s' % MY_ACCOUNT_NAME, update=1)
> if cartodb_ds is None:
>     print 'Cannot open CartoDB connection for writing'
> 
> cartodb_layer = cartodb_ds.CreateLayer('my_layer',
> geom_type=ogr.wkbMultiPolygon)
> 
> 
> Activating debug, this is what the driver sends to CartoDB:
> 
> q=CREATE TABLE "my_layer" ( cartodb_id SERIAL, the_geom
> GEOMETRY(MULTIPOLYGON, 0), the_geom_webmercator GEOMETRY(MULTIPOLYGON,
> 3857),PRIMARY KEY (cartodb_id) );DROP SEQUENCE IF EXISTS
> "my_layer_cartodb_id_seq";CREATE SEQUENCE "my_layer_cartodb_id_seq"
> START 1;ALTER TABLE my_layer ALTER COLUMN cartodb_id SET DEFAULT
> nextval('my_layer_cartodb_id_seq')&api_key=1f1464a7f041a39568046b858af425ab
> ab4fefc6
> 
> 
> And the response error message (HTTP error 400):
> 
> CARTODB: RunSQL Response:{"error":["cannot drop sequence
> my_layer_cartodb_id_seq because other objects depend on it"]}

Perhaps use DROP CASCADE intead of DROP ?
Feel free to modify the driver.

> 
> If I get rid of all the SQL after the create table sentence itself, it
> works, and the table is created. I guess I could modify the driver to
> avoid this, but I'd like to know if someone is using it and having
> this problem.
> 
> BTW, the tables created via SQL API don't appear in the CartoDB
> dashboard, but this is a known issue (
> https://github.com/CartoDB/cartodb/issues/115)
> 
> Best regards,

-- 
Geospatial professional services
http://even.rouault.free.fr/services.html


More information about the gdal-dev mailing list