1

In the QGIS 3.34+ expression builder, how could one use the expression parameter in the relation_aggregate to fetch multiple fields?

E.g.:

relation_aggregate( 
    relation:= 'my_relation', 
    aggregate:= 'array_agg', 
    expression:= "rep_lyr,rep_id",
    concatenator:= "; "
)

but this doesn't work.

The goal is to fetch related data in a many to many join table as follow:

id ref_id rep_lyr rep_id
1 1 lyrB 2
2 1 lyrC 3
3 4 lyrB 7
4 5 lyrA 8
5 9 lyrB 11
6 7 lyrB 11

I'm trying to set up labels for my features:

enter image description here

1
  • 1
    "rep_lyr,rep_id"is not a valid expression nor a valid field name, could you give an exemple of what you want as result ?
    – J.R
    Commented Feb 26 at 12:43

1 Answer 1

3

One option is to concatenate the field values like so:

relation_aggregate( 
    relation:= 'my_relation', 
    aggregate:= 'array_agg', 
    -- field values concatenated into a string separated by a comma
    expression:= "rep_lyr" || ',' || "rep_id"
)

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