[Qgis-user] New Labeling: conditional labels
Mayeul Kauffmann
mayeul.kauffmann at free.fr
Fri Jan 6 06:40:14 PST 2012
Martin wrote:
>I would suggest to implement the CASE statement
Yes that would be great!!
CASE also supports another syntax which is even more flexible:
CASE WHEN a=1 THEN 'one'
WHEN a=2 THEN 'two'
ELSE 'other'
END
instead of:
CASE a WHEN 1 THEN 'one'
WHEN 2 THEN 'two'
ELSE 'other'
END
(example from [2]).
The first syntax allows to create conditions based on several fiels, like in the rule based renderer, for instance:
CASE WHEN a=1 AND b=2 THEN 'one'
WHEN c=3 THEN 'two'
ELSE 'other'
END
Cheers,
Mayeul
Le vendredi 06 janvier 2012 à 13:25 +0100, Martin Dobias a écrit :
> Hi
>
> On Thu, Dec 29, 2011 at 11:33 AM, Nathan Woodrow <madmanwoo at gmail.com> wrote:
> > It would be handy to add condition statements to QgsExpression so we can
> > support this kind of thing, Martin would be the guy to talk to about adding
> > this kind of thing. He knows the most about QgsExpression.
>
> SQL recognizes CASE statement with following alternate syntax:
>
> 1. "if" equivalent:
> CASE
> WHEN x > 10 THEN 'big' ELSE 'small'
> END
>
> 2. "switch" equivalent:
> CASE x
> WHEN 5 THEN 'five'
> WHEN 6 THEN 'six'
> ELSE 'something else'
> END
>
> The "else" is not required, if there is no matching "when" then NULL
> is returned.
>
> Some SQL engines add further functions for convenience:
> - MySQL [1]: IF(), IFNULL(), NULLIF()
> - PostgreSQL [2]: COALESCE(), NULLIF()
>
> I would suggest to implement the CASE statement to stay compliant with
> SQL syntax (although I find It a bit verbose).
>
> Regards
> Martin
>
> [1] http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html
> [2] http://www.postgresql.org/docs/8.1/static/functions-conditional.html
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
More information about the Qgis-user
mailing list