[GIS] Using wildcards for column headers in QGIS Field Calculator

attribute-joinsattribute-tablefield-calculatorqgiswildcard

I know you can use wildcards for fields like so (in the Field Calculator):

case when "column" ILIKE '%example%' then 1
else 0
end

Can you do something similar for the column headers themselves?

I ask this because I'm joining several layers (using the Joins properties) and it would make it easier for me to edit one set of filters instead of editing several filters since the column names will have to include the joined layer name.

I'm using QGIS 2.2.

Best Answer

With the introduction of the Function Editor back in QGIS 2.8, it is possible to iterate through the field names and perform some sort of analysis:

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def fields(feature, parent):
    layer = qgis.utils.iface.activeLayer()
    field_names = [field.name() for field in layer.fields()]
    for name in field_names:
        if "some_name" in name:
            # Do something
Related Question