3

I must do a view in geoserver. I seen some example here: http://docs.geoserver.org/stable/en/user/data/database/sqlview.html. The example show the operator like for parameterizing view. Suppose, now that in WFS request there is a value for a field (named filed1) example &viewparams=value1:a. If i use the operator like

Select filed1, filed2, field3 
From myTable 
where field1 like %value1% 

the view return tuples where filed1 is a, aa, aaa, aaaa, aaaaa, etc, but i want tuples where filed1='a'. Can i use the operator =, if yes how write my query?

Select filed1, filed2, field3 
From myTable 
where field1 = .......
GIS-Jonathan
6,7855 gold badges31 silver badges58 bronze badges
asked Nov 2, 2012 at 11:45
1
  • Some challenges related to parameters in WMS and standardization is mentioned here: mindland.com/wp/… Commented Dec 2, 2012 at 12:51

2 Answers 2

2

From the page you link to:

Within the SQL View query, parameter names are delimited by leading and trailing % signs. The parameters can occur anywhere within the query text, including such uses as within SQL string constants, in place of SQL keywords, or representing entire SQL clauses.

So I suspect you can do:

Select filed1, filed2, field3 
From myTable 
where field1 = %value1%
answered Nov 2, 2012 at 11:51
7
  • Iant, my query is: Select uri_placeinst, ST_AsText(coord_placeinst) as coord_place_inst From public."NewInfoGeometric" where uri_contesto = %urlcont% and GeometryType(ST_AsText(coord_placeinst)) = %typegeom% and tipofeature=%typefeat% . After click on Refresh for convalidate i have ERROR: syntax error at or near "and" Posizione: 141 Commented Nov 2, 2012 at 13:04
  • and what do you want me to do about it? look in the log file to see what the actual sql query sent was and use that information to fix your syntax. Commented Nov 2, 2012 at 13:19
  • because you responded to my post I thought you might like to know that your suggestion is not the right way to parameterize a request. what to do? anything! Commented Nov 2, 2012 at 13:24
  • No, the parameterization is correct your sql syntax is wrong Commented Nov 2, 2012 at 13:31
  • I solved my problem. SQL query is right, the parameterization is wrong, however thanks for your reply. Commented Nov 2, 2012 at 13:38
0

If the sql command:

Select 
 uri_placeinst, 
 ST_AsText(coord_placeinst) as coord_place_inst 
From 
 public."NewInfoGeometric" 
where 
 uri_contesto = %urlcont% 
 and GeometryType(ST_AsText(coord_placeinst)) = %typegeom% 
 and tipofeature=%typefeat%

The expression GeometryType(ST_AsText(coord_placeinst)) returns a string perhaps you need to put single quotes around the %typegeom% expression.

nagytech
3,76120 silver badges37 bronze badges
answered Jul 1, 2015 at 9:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.