Search code examples
postgresqlviewpostgisgeoserver

Geoserver sql view parameters messing up postgis function calls


I have setup an openlayers html window that communicates with the geoserver platform. Geoserver is connected to the database through a parametric view where the entire "where" clause is a parameter.

My problem is that when I create an sql query on my database, of the form "Select b.the_geom from "Beta" b where b.point_id < 100" it works.

If I send a view parameter to geoserver:

  • > Select b.the_geom from "Beta" b %parameter% < -

and the parameter is the where clause of the sql query I just demonstrated in the beginning, everything works perfectly.

So I know that my program can send the parameter (the complete "where" clause) and figure the query out. For example, it shows 3 out of 4 points when the id is < 40 and all 4 if the id is < 100.

However, when I use any postgis function to compare geometries, the sql query inside pgadmin works perfectly, and returns the same kind of data as the successful query in the first section. For example, it returns all the geometries with the same the_geom numbers.

However, when I actually send the where clause that includes a postgis function like ST_CROSSES(b.the_geom,c.the_geom) from html to the geoserver, nothing shows in the openlayers window.

How could this be?


Solution

  • Ok, in case anybody happens to have the same question, after looking through the logs as suggested I found the culprit. Geoserver complained about having two parameters, meaning the comma inside the where clause had to be escaped. After looking at others with similar problems, I found that you have to escape the comma three times, "\ \ \," essentially making sure that a "\," will remain escaped after you send the request through javascript.