1

As part of my model I union a bunch of PostGIS layers (views), each containing the same 'feature' field (char(64)). After the union, there are a numerous feature_2, feature_3 etc etc fields in the output. Example View: Example View Model Model I want to store these values into the original 'feature' field but the field calculator does not recognise the fields?

Field Calculator- Pre Calculated Value

CASE
WHEN "feature_2" IS NOT NULL THEN '1'
WHEN "feature_3" IS NOT NULL THEN '2'
WHEN "feature_4" IS NOT NULL THEN '3'
WHEN "feature_5" IS NOT NULL THEN '4'
WHEN "feature_6" IS NOT NULL THEN '5'
WHEN "feature_7" IS NOT NULL THEN '6'
END

Result

feature setback calc: Field 'feature_2' not found Example output of the union: Example union output

Creating a temporary output from the model from the same step that the field calculator uses shows that these fields DO exist? What's going on here?

3
  • 1
    Can you provide some practical example of your views & union result. Why isn't the union query defined to report 'feature' of each view, in the resulting 'feature' column if that's your need?
    – Kasper
    Commented Jan 11, 2023 at 7:38
  • Can you provide the model? Otherwise, we have to speculalte what you're doing.
    – Babel
    Commented Jan 11, 2023 at 8:22
  • @Kasper- Updated to include some pictures. Re the field calculator, I do actually want to update the existing 'feature' column with the value of the 'feature_x' column if it isn't null. The example above was me just reverting to try and get something in that column/debugging.
    – Tim
    Commented Jan 11, 2023 at 19:21

1 Answer 1

0

I found the solution to this problem was not to use a CASE but to use a COALESCE into the final field (planting_class) which will use the temporary field names (planting_class_1 2 3 etc):

coalesce("planting_class_2",
"planting_class_3",
"planting_class_4",
"planting_class_5",
"planting_class_6",
"planting_class_7",
"planting_class_8",
"planting_class_9", 
"planting_class")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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