[Qgis-user] SQL Expressions

Nyall Dawson nyall.dawson at gmail.com
Mon Mar 30 05:20:09 PDT 2015


On 30 March 2015 at 23:07, Junior Delaz <delazj at gmail.com> wrote:
>
> Hi,
> Niccolo, Nathan is right. his proposal is the simplier and recommanded.
> But I think your formulae should work if you write
> $atlasfeatureid || '_' || attribute($atlasfeature, 'name' ).
> Only simple quote ' and not " near the field's name inside attribute function brackets.
>
> By the way, can someone explain me why for some functions (attribute, getFeature), you need to use simple quote for the fields and double quotes when using other functions ?
> And when you double-click on field's name, they are always appended to your expression with double quote. Can this be standardised ?
>

Double quotes will give you the value of that field. It's standard
behaviour. But when you write:

attribute($atlasfeature, "name" )

you're actually saying "fetch the value of the attribute named 'name',
and then get the attribute from $atlasfeature which is called that
value". Eg, if your feature's 'name' field has a value "New York",
then the expression will be retrieving the value of the "new york"
attribute from $atlasfeature. Most likely your feature doesn't have an
attribute called "New York", so nothing is returned.

The single quote is a literal. So:

attribute($atlasfeature, 'name' )

means "fetch the attribute from $atlasfeature which is called 'name'".
So this would return "New York".

Hope that helps clarify!
Nyall



More information about the Qgis-user mailing list