I'd like to select multiple values on my column (undefined number) and as long as I know, IN operator doesn't work on Mapserver's filter.

Example : FILTER (([ct] IN ('%ct%')) or ('%ct%' = '1')) returns

msPostGISLayerWhichShapes(): Error (ERREUR: la fonction ct(unknown) n'existe pas LINE 1: ...0878906249999975 -66.4782081438564))',4326) and (("ct"('1'))...

HINT: Aucune fonction ne correspond au nom donné et aux types d'arguments. Vous devez ajouter des conversions explicites de type.

==> ct(unknown) function doesn't exist ... Can't find a function matching name and parameters given. You should add explicite type's conversions

Is there a tip to use IN operator? I need to send several values for a same column.

As my filter function could seem strange, here's my VALIDATION :

    'ct' '^[a-zA-Z\-]+$'
    'default_ct' '1'
  • What did you use as an example for your FILTER? Is it from MapServer documentation? – user30184 Oct 20 '16 at 12:37
  • @user30184 Kinda. I needed to have my filter always returning true. See my question here : stackoverflow.com/questions/40149799/… – So4ne Oct 20 '16 at 12:39
  • @user30184 I added my VALIDATION in my question to help you understand :) – So4ne Oct 20 '16 at 12:41
  • I don't quite get what you plan to do. Converted into SQL, is it select * from my_table where ct in ('user_given_string') OR user_given_string='1'? – user30184 Oct 20 '16 at 13:02
  • > select * from my_table where ct in ('user_given_string') OR '1'='1' This is because I didn't know how to don't use my filter at the launch of the application. With Openlayers, I don't send ct as parameter, only when I click on a button, so MapServer tried to filter and sent me a map with no dataset, like ct = ' '. I actually don't know how to explain better, except if you're french ^^ POint is everything works fine for select * from my_table where ct = 'user_given_string' OR '1'='1', but doesn't work when I put an IN instead of = – So4ne Oct 20 '16 at 13:06

MapServer gets confused with this validation

    'ct' '^[a-zA-Z\-]+$'
    'default_ct' '1'

The first line means "any string of any length that contain only ASCII letters in upper or lower case". However, on the second line the default value is set to '1' which does not validate by the regexp '^[a-zA-Z-]+$'.

You can either correct the regexp to accept also '1' or change the default to for example 'a'. FILTER must be edited to suit this change as or ('%ct%' = 'a').

The syntax of filters and expressions in MapServer is somewhat peculiar. Because your backend is PostGIS you can use the normal SQL syntax by forcing MapServer to use native filters. As documented in http://mapserver.org/mapfile/layer.html it is done with processing - ative filter directive

  • This directive can be used to do driver specific filtering. For database connections the string is a SQL WHERE clause that is valid with respect to the underlying database.

In your case use


You can try using Class Expression as documented in http://www.mapserver.org/mapfile/expressions.html#string-expressions-that-return-a-logical-value

As explained in that documentation whenever you are going to use IN- clause you simply have to use in this way

FILTER ('[SITE]' IN 'U0118,U2257,U2550')

Here the key point to notice is that all your values for IN clause should be enclosed in single inverted commas i.e. you need not to add a single inverted comma for every token of IN clause.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.