artemp/trac2github — Issue #261: Improve flexibility and reliability of PostGIS SQL/Query handling
Author: artemp
Created: 2011-10-09 20:23:50+00:00
State: open
Labels: PostGIS_Input_Driver

The postgis input plugin uses function postgis_datasource::table_from_sql to obtain the table name used in a select query. This function searches for the last occurrence of "from" in the query, and takes the next word as the table name.

This method fails, if, after the real "from", the query contains another from, even if that is part of a word (e.g. ST_GeomFromText function). It might also fail (or yields questionable results), if the query joins two or more tables, or has sub-selects (although handling this might require larger changes and thus be a different topic).

The attached patch works in my case, by checking for the last occurrence of " from " (ie. with spaces around). But it might need further improvement, because cases are possible, where the from is not delimited by spaces.

If unhandled, the layers containing the described queries are not shown at all (silently ignored).