[gdal-dev] Retreivinng a table with a condition using ogr2ogr OCI

Even Rouault even.rouault at spatialys.com
Tue Apr 21 02:36:19 PDT 2015


Le mardi 21 avril 2015 11:08:53, Ammar a écrit :
> Hello all,
> I am using ogr2ogr OCI driver to convert an Oracle table to a shape file.
> The command I am using is (it works perfectly):
> 
> ogr2ogr 3011 -f "ESRI Shapefile" OCI:"user/password@(DESCRIPTION =
> (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT =
> 1521)))(CONNECT_DATA = (SID =MY_SID))):TABLE"
> 
> Now, I am trying to use the -sql option so that to retrieve a table only if
> the condition is true but I am having trouble getting the command to work.
> The command I'm using is: ogr2ogr 3011 -f "ESRI Shapefile"
> OCI:"user/password@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL =
> TCP)(HOST = 127.0.0.1)(PORT = 1521)))(CONNECT_DATA = (SID
> =MY_SID))):TABLE"  -sql "SELECT * FROM TABLE WHERE DETAILTYPE =
> 'Something'" and I am getting the following error message:
> layer names ignored in combination with -sql.
> ERROR 1: Failed to create file .shp file.
> ERROR 4: Failed to open Shapefile `3011\SELECT * FROM TABLE WHERE
> DETAILTYPE = 'Something'.shp'.

Ammar,

it seems that the resulting layer from the SQL query is called "SELECT * FROM 
TABLE WHERE ....", which is a bit an unfortunate choice (other drivers 
generally call it "result" or "sql_statement", etc...
Anyway, add "-nln the_layer_name_you_like" to avoid this.
Alternatively you can add  -where "DETAILTYPE = 'Something'" in your first 
ogr2ogr command that operates on the table, as opposed to a full SQL request.

Even

> 
> ERROR 1: Terminating translation prematurely after failed
> translation from sql statement.
> How can I get ogr2ogr to work with -sql?
> 
> I am using GDAL 1.11.1, released 2014/09/24 on Windows 64-bits.
> Thanks in advanceAmmar

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list