[Geoserver-users] Multiple viewparams not working: &viewparams=p1:5; p2:6; p3:7

Hi all

I am following the documentation at https://docs.geoserver.org/latest/en/user/data/database/sqlview.html#using-a-parametric-sql-view which is essentially:

Using a parametric SQL View

The SQL view parameters are specified by adding the viewparams parameter to the WMS GetMap or the WFS GetFeature request. The viewparams argument is a list of key:value pairs, separated by semicolons:

viewparams=p1:v1;p2:v2;...

If the values contain semicolons or commas these must be escaped with a backslash (e.g. \, and \;).

I have discovered that the second and third viewparams (p2, p3 above) do not get set to the values provided in the WFS request and default to their default values.

How to reproduce:

Add store > Geopackage (which allows a SQL view) > test-viewparams as the store name and geopackage name
You will be taken to Add new layer > Configure new SQL view > add a view name and this SQL:

SELECT %p1% as a,
%p2% as b,
%p3% as c

Click Guess parameters from SQL > enter default values 1, 2, 3 respectively. Save, Save.

image.png

Now hit
http://localhost:8080/geoserver/wfs?version=1.0.0&request=GetFeature&typeName=cite:test-viewparams&outputFormat=application/json&viewparams=p1:5;p2:6;p3:7

This should set:

  • p1 to 5 (not the default 1)
  • p2 to 6 (not the default 2)
  • p3 to 7 (not the default 3)
    However, only p1 is set and p2 and p3 are set to their default values:

{
“type”: “FeatureCollection”,
“features”: [{
“type”: “Feature”,
“id”: “test-viewparams.fid-42816c8f_1842d011d2b_-7ff3”,
“geometry”: null,
“properties”: {
“a”: 5,
“b”: 2,
“c”: 3
}
}
],
“totalFeatures”: 1,
“numberMatched”: 1,
“numberReturned”: 1,
“timeStamp”: “2022-11-10T09:29:59.900Z”,
“crs”: null
}

Can anyone explain why this is not working, please?

Thank you

Peter