Bug report #16419

Virtual layers SQL output fields without alias raise errors

Added by Giovanni Allegri almost 7 years ago. Updated about 5 years ago.

Status:Feedback
Priority:Normal
Assignee:-
Category:DB Manager
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:24328

Description

Calculated fields inside Virtual Layers SQL queries (through DB Manager) must have an alias otherwise it raises errors.
The problem is that it can't be deduced from the error message.

As an example:

SELECT
ST_Area("landcover"."geometry")
FROM "landcover"

will raise the message "Query preparation error on SELECT "ST_Area("comuni"."geometry")" FROM _tview LIMIT 1: near ""."": syntax error"

(you can see it in the vlayer.png image attachment)

The query works fine if an alias is added:

SELECT
ST_Area("landcover"."geometry") AS area
FROM "landcover"

I guess that the fix could be to use the field function as a string and use it for the output field name (as DBs do)

vlayer.png (26.3 KB) Giovanni Allegri, 2017-04-07 12:06 AM

History

#1 Updated by Giovanni Manghi almost 7 years ago

  • Easy fix? set to No
  • Regression? set to No

#2 Updated by Giovanni Manghi about 5 years ago

  • Status changed from Open to Feedback

Please check if this issue is still valid on QGIS 3.4.5 or 3.6.

Also available in: Atom PDF