Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute and load SQL processing algorithm fails if statement includes semi colon #30239

Closed
timlinux opened this issue Jun 16, 2019 · 2 comments · Fixed by #30333
Closed

Execute and load SQL processing algorithm fails if statement includes semi colon #30239

timlinux opened this issue Jun 16, 2019 · 2 comments · Fixed by #30333
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Processing Relating to QGIS Processing framework or individual Processing algorithms

Comments

@timlinux
Copy link
Member

Environment: QGIS 3.4.8 on macOS

It is common practice to include a semi-colon at the end of an SQL statement. However when doing this in the 'Execute and load SQL' processing algorithm, the algorithm fails with a cryptic message:

image

Loading resulting layers
Algorithm 'PostgreSQL execute and load SQL' finished
Processing algorithm…
Algorithm 'PostgreSQL execute and load SQL' starting…
Input parameters:
{ 'DATABASE' : 'Dominica on Postgres.app', 'GEOMETRY_FIELD' : 'geom', 'ID_FIELD' : 'id', 'SQL' : 'select id, geom, distance from potential_site_points;' }

Traceback (most recent call last):
File "/Applications/QGIS3.4.app/Contents/MacOS/../Resources/python/plugins/processing/algs/qgis/PostGISExecuteAndLoadSQL.py", line 114, in processAlgorithm
Please check the PostGIS log for error messages."""))
_core.QgsProcessingException: This layer is invalid!
Please check the PostGIS log for error messages.

Execution failed after 0.07 seconds

Loading resulting layers
Algorithm 'PostgreSQL execute and load SQL' finished
Processing algorithm…
Algorithm 'PostgreSQL execute and load SQL' starting…
Input parameters:
{ 'DATABASE' : 'Dominica on Postgres.app', 'GEOMETRY_FIELD' : 'geom', 'ID_FIELD' : 'id', 'SQL' : 'select id, geom, distance from potential_site_points' }

Execution completed in 0.11 seconds
Results:
{'OUTPUT': 'layername_4c541080_d310_497c_ac7d_3bdf7bb357fd'}

Loading resulting layers
Algorithm 'PostgreSQL execute and load SQL' finished

I enabled logging in my PostGIS instance and saw the issue was caused by a stray semi-colon:

2019-06-16 17:27:59.880 WEST [15809] STATEMENT:  
SELECT * FROM (select id, geom, distance from potential_site_points;) AS "subQuery_0" LIMIT 1

Using the tool again with no semi-colon allows the statement to run successfully:

image

Algorithm 'PostgreSQL execute and load SQL' starting…
Input parameters:
{ 'DATABASE' : 'Dominica on Postgres.app', 'GEOMETRY_FIELD' : 'geom', 'ID_FIELD' : 'id', 'SQL' : 'select id, geom, distance from potential_site_points' }

Execution completed in 0.11 seconds
Results:
{'OUTPUT': 'layername_4c541080_d310_497c_ac7d_3bdf7bb357fd'}

Loading resulting layers
Algorithm 'PostgreSQL execute and load SQL' finished
Processing algorithm…
Algorithm 'PostgreSQL execute and load SQL' starting…
Input parameters:
{ 'DATABASE' : 'Dominica on Postgres.app', 'GEOMETRY_FIELD' : 'geom', 'ID_FIELD' : 'id', 'SQL' : 'select id, geom, distance from potential_site_points' }

Execution completed in 0.10 seconds
Results:
{'OUTPUT': 'layername_88c8b485_7f29_44e9_ab2d_a62a22d5ab63'}

Loading resulting layers
Algorithm 'PostgreSQL execute and load SQL' finished
@timlinux timlinux added Processing Relating to QGIS Processing framework or individual Processing algorithms Bug Either a bug report, or a bug fix. Let's hope for the latter! labels Jun 16, 2019
@timlinux
Copy link
Member Author

Note also that the 'PostgreSQL Execute SQL' algorithm works with a semi colon at the end of the statement.

alexbruy added a commit that referenced this issue Jun 23, 2019
[processing] remove trailing semicolon from SQL before creating a layer (fix #30239)
alexbruy added a commit that referenced this issue Jun 23, 2019
[Backport release-3_8] [processing] remove trailing semicolon from SQL before creating a layer (fix #30239)
@timlinux
Copy link
Member Author

Thanks @alexbruy !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Processing Relating to QGIS Processing framework or individual Processing algorithms
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant