Bug #5883
Erroneous query: zero-length delimited identifier at or near """"
| Status: | Closed | Start Date: | 06/27/2012 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assigned to: | % Done: | 0% |
||
| Category: | PostGIS Data Provider | |||
| Target version: | Version 2.0.0 | |||
| Platform: | Patch supplied: | No | ||
| Platform version: | Affected version: | 1.8.0 | ||
| Status info: | Causes crash or corruption: | No | ||
| Resolution: |
Description
SQL window, retriving the data worked, loading as layer didn't (but didn't visually report any error)
Error/debug on the console:
Debug: src/providers/postgres/qgspostgresprovider.cpp: 2683: (getGeometryDetails) Getting geometry column: SELECT "geom" FROM (select (ST_Dump(ST_DelaunayTriangles(st_collect(cell)))).* FROM hexagrid
) AS "subQuery_0" LIMIT 0
Debug: src/providers/postgres/qgspostgresconn.cpp: 1063: (retrieveLayerTypes) Retrieving geometry types: SELECT DISTINCT CASE WHEN upper(geometrytype("geom")) IN ('POINT','MULTIPOINT','POINTM','MULTIPOINTM') THEN 'POINT' WHEN upper(geometrytype("geom")) IN ('LINESTRING','MULTILINESTRING','LINESTRINGM','MULTILINESTRINGM') THEN 'LINESTRING' WHEN upper(geometrytype("geom")) IN ('POLYGON','MULTIPOLYGON','POLYGONM','MULTIPOLYGONM') THEN 'POLYGON' END, st_srid("geom") FROM (SELECT "geom" FROM ""."(select (ST_Dump(ST_DelaunayTriangles(st_collect(cell)))).* FROM hexagrid
) AS ""subQuery_0""" WHERE "geom" IS NOT NULL LIMIT 100) AS t
Debug: src/core/qgsmessagelog.cpp: 41: (logMessage) 2012-06-27T18:03:17 PostGIS[0] Erroneous query: SELECT DISTINCT CASE WHEN upper(geometrytype("geom")) IN ('POINT','MULTIPOINT','POINTM','MULTIPOINTM') THEN 'POINT' WHEN upper(geometrytype("geom")) IN ('LINESTRING','MULTILINESTRING','LINESTRINGM','MULTILINESTRINGM') THEN 'LINESTRING' WHEN upper(geometrytype("geom")) IN ('POLYGON','MULTIPOLYGON','POLYGONM','MULTIPOLYGONM') THEN 'POLYGON' END, st_srid("geom") FROM (SELECT "geom" FROM ""."(select (ST_Dump(ST_DelaunayTriangles(st_collect(cell)))).* FROM hexagrid
) AS ""subQuery_0""" WHERE "geom" IS NOT NULL LIMIT 100) AS t returned 7 [ERROR: zero-length delimited identifier at or near """"
LINE 1: ...ON' END, st_srid("geom") FROM (SELECT "geom" FROM ""."(selec...
^
Associated revisions
History
Updated by Paolo Cavallini 11 months ago
- Assigned to set to Giuseppe Sucameli
Updated by Giuseppe Sucameli 11 months ago
- Category changed from DBManager to PostGIS Data Provider
It's a bug on the PG provider. The schema part is added also for queries (a check is missing).
Updated by Jürgen Fischer 11 months ago
SQL window, retriving the data worked, loading as layer didn't (but didn't visually report any error)
Can you reproduce the problem with something that doesn't need the latest postgis?
BTW you should "visually" see the error in the message log (and the popup over the in the main window status bar).
Updated by James Stott 11 months ago
I have changed my code slightly from the original code I posted on the mailing list and I get a slightly different error:
This query works and adds a layer into QGIS:
uri.setDataSource('',"(SELECT int4(row_number() OVER ()) AS id,ST_GeomFromText('POINT(451583 129144)',27700) As geom)", "geom",'',"id")
The following doesn't work:
uri.setDataSource('',"(SELECT * From \"designations\".\"table\" where ST_DWithin(ST_GeomFromText('POINT(451583 129144)',27700), \"table\".\"geom\", 2000)", "geom",'',"gid")
This gives the following error:
Unable to execute the query.
The error message from the database was:
ERROR: syntax error at or near "AS"
LINE 1: ... 129144)',27700), "listed_building"."geom", 2000) AS "subQue...
^
.
SQL: SELECT * FROM (SELECT * From "designations"."listed_building" where ST_DWithin(ST_GeomFromText('POINT(451583 129144)',27700), "listed_building"."geom", 2000) AS "subQuery_0" LIMIT 1
Does seem like there is an extra SELECT statement added to the from of the query as it says SELECT * FROM (SELECT * From. The from in my code is From not FROM.
Updated by Jürgen Fischer 11 months ago
James Stott wrote:
The following doesn't work:
uri.setDataSource('',"(SELECT * From \"designations\".\"table\" where ST_DWithin(ST_GeomFromText('POINT(451583 129144)',27700), \"table\".\"geom\", 2000)", "geom",'',"gid")
And that's not just because the closing paren is missing after "2000)"?
Updated by James Stott 11 months ago
Adding the ) leads to this error:
Unable to execute the query.
The error message from the database was:
ERROR: subquery in FROM must have an alias
LINE 1: SELECT * FROM (SELECT * From designations.listed_building wh...
^
HINT: For example, FROM (SELECT ...) [AS] foo.
.
SQL: SELECT * FROM (SELECT * From designations.listed_building where ST_DWithin(ST_GeomFromText('POINT',27700), listed_building.geom, 2000)), geom,'',gid) AS "subQuery_0" LIMIT 1
Updated by Jürgen Fischer 11 months ago
James Stott wrote:
SQL: SELECT * FROM (SELECT * From designations.listed_building where ST_DWithin(ST_GeomFromText('POINT',27700), listed_building.geom, 2000)), geom,'',gid) AS "subQuery_0" LIMIT 1
Please check the syntax again. Looks like you misplaced the " this time ;)
Updated by James Stott 11 months ago
Apologies, it was a syntax problem.
This worked:
query = "(SELECT * From \"designations\".\"table\"where ST_DWithin(ST_GeomFromText('POINT(" + str(self.dlg.getEasting()) + " " + str(self.dlg.getNorthing()) + ")',27700), \"table\".\"geom\","+ self.dlg.getBuffSize() +"))"
uri.setDataSource('', query, "geom",'',"gid")
Updated by Paolo Cavallini 9 months ago
- Target version set to Version 2.0.0
Updated by Giuseppe Sucameli 8 months ago
- Status changed from New to Feedback
Jürgen Fischer wrote:
SQL window, retriving the data worked, loading as layer didn't (but didn't visually report any error)
Can you reproduce the problem with something that doesn't need the latest postgis?
BTW you should "visually" see the error in the message log (and the popup over the in the main window status bar).
strk, could you please provide more info?
Updated by Sandro Santilli 8 months ago
This query doesn't need the latest postgis, nor any table:
select (ST_Dump(ST_ConvexHull(st_collect('POINT(0 0)'::geometry)))).*
Try it, replacing "unioned" and "wrongsnap" with a valid geometry column and table name.
It's still failing as of:
QGIS version 1.9.0-Master QGIS code revision fe8385e Compiled against Qt 4.8.1 Running against Qt 4.8.1 Compiled against GDAL/OGR 2.0dev Running against GDAL/OGR 2.0dev GEOS Version 3.4.0dev PostgreSQL Client Version 9.1.5 SpatiaLite Version 2.4.0 QWT Version 5.2.2 PROJ.4 Version 480 This copy of QGIS writes debugging output.
I still tried trough the DBManager, don't know if it's possible (or how) to reproduce directly against the PostGIS Data Provider. Maybe Giuseppe knows ?
Updated by Giuseppe Sucameli 8 months ago
Sandro Santilli wrote:
I still tried trough the DBManager, don't know if it's possible (or how) to reproduce directly against the PostGIS Data Provider. Maybe Giuseppe knows ?
Try the following code from QGis Python Console:
uri = QgsDataSourceURI() uri.setConnection(host, u"%s" % port, dbname, user, passw) uri.setDataSource( "", u"(%s\n)" % query, geomcol, "", keycol ) vl = QgsVectorLayer( uri.uri(), "layername", "postgres" ) QgsMapLayerRegistry.instance().addMapLayer( vl )
Updated by Jürgen Fischer 8 months ago
Giuseppe Sucameli wrote:
Try the following code from QGis Python Console: [...]
Should that reproduce the problem? Because it doesn't here.
Updated by Giuseppe Sucameli 8 months ago
Jürgen Fischer wrote:
Giuseppe Sucameli wrote:
Try the following code from QGis Python Console: [...]
Should that reproduce the problem? Because it doesn't here.
I know, neither here. But that code is quite identical to the one used in DBManager.
Updated by Sandro Santilli 8 months ago
I've no time to debug this. Can't you reproduce it there Giuseppe ?
Updated by Giuseppe Sucameli 8 months ago
- Status changed from Feedback to New
- Assigned to changed from Giuseppe Sucameli to Jürgen Fischer
Sandro Santilli wrote:
I've no time to debug this. Can't you reproduce it there Giuseppe ?
Not reproduced yet, anyway I've found it.
The problem is at https://github.com/qgis/Quantum-GIS/blob/master/src/providers/postgres/qgspostgresconn.cpp#L1027, so you're using estimated metadata for the connection.
@Jef: I've assigned the ticket to you, I don't know how to handle estimated metadata option together with queries.
Updated by Sandro Santilli 8 months ago
No way to estimate extent of a query. You must necessarely run it.
Updated by Sandro Santilli 8 months ago
Updated by Giuseppe Sucameli 8 months ago
select 1 as id, (ST_Dump(ST_ConvexHull(st_collect('POINT(0 0)'::geometry)))).* FROM "mytablename"
It works until the "use table estimated metadata" option is checked in the connection settings, in that case I get the following error:
Erroneous query: SELECT DISTINCT CASE WHEN upper(geometrytype("geom")) IN ('POINT','MULTIPOINT','POINTM','MULTIPOINTM') THEN 'POINT' WHEN upper(geometrytype("geom")) IN ('LINESTRING','MULTILINESTRING','LINESTRINGM','MULTILINESTRINGM') THEN 'LINESTRING' WHEN upper(geometrytype("geom")) IN ('POLYGON','MULTIPOLYGON','POLYGONM','MULTIPOLYGONM') THEN 'POLYGON' END, st_srid("geom") FROM (SELECT "geom" FROM ""."(select 1 as id, (ST_Dump(ST_ConvexHull(st_collect('POINT'::geometry)))).* FROM ""province""
) AS ""subQuery_0""" WHERE "geom" IS NOT NULL LIMIT 100) AS t returned 7 [ERROR: zero-length delimited identifier at or near """"
LINE 1: ...ON' END, st_srid("geom") FROM (SELECT "geom" FROM ""."(selec...
^
]
EDIT:
the problem occurs also with very simple queries like:
SELECT 1 as "id", 'POINT(1 10)'::geometry as "geom"
Updated by Jürgen Fischer 8 months ago
- Status changed from New to Closed
Fixed in changeset 6aa7524482f176aaf603ff47b171a1c3e3c2fc62.