A parametric SQL view is based on a SQL query containing the named parameters with values provided dynamically in WMS and WFS requests.
ContinentView
as View Name and the following code as the SQL statement:SELECT ADMIN, GEOM FROM COUNTRIES WHERE CONTINENT = '%continent%'
Africa
as the default value.&viewparams=continent:Europe
to your request URL and reload the map. You should now see a different map:A parametric view lets you define one or more filtering parameters at request time. In this recipe, instead of building five different views (one for each continent), we have a single view, and the calling app can define which continent is relevant in the request.
Building a parametric view is not different from a standard SQL view. You can start creating the code without any parameters to check that you have no syntax or logical errors.
Once you are done with the code, you can select which field should become a parameter. To let GeoServer recognize the parameters, you simply enclose them within %
characters, as shown in the following code:
WHERE CONTINENT = '%continent%'
GeoServer recognizes the parameters and lets you set an optional default value. Please note that if you don't set a default value, you always need to set a value for parameters when sending a request to GeoServer.
At run time, you set values for each parameter, adding the viewparams
option to your request. As per the value of the option, you insert a set of params-value
couples.
3.147.74.211