1
votes

I am putting JSON values into a Postgres database, chaining InvokeHTTP, CovertJSONtoSQL, ReplaceText and PutSQL. The ReplaceText is adding an additional 'ON CONFLICT...' clause to my SQL.

As part of the ReplaceText, I'm using one of the sql attributes of the flowfile, which as far as I can tell is being persisted as a boolean (attribute is shown as 't' or 'f' in the flowfile). I need to convert this boolean (t or f) to a string ("TRUE" or "FALSE") in order that it works in my query. My tactic was to try ifelse() as in

${sql.args.3.value:ifElse("TRUE","FALSE")}

That always returns "FALSE" even when the attribute value it 't'.

I've made it work by casting it to a string first:

${sql.args.3.value:toString():equals('t'):ifElse("TRUE","FALSE")}

but I'm frustrated that it doesn't seem to work as expected. Any ideas?

Thanks!

1

1 Answers

5
votes

This seems like expected behavior based on the documentation of ifelse:

https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#ifelse

If sql.args.3.value contained the value "true" or "false" then it would be interpreted as a boolean, such as in the example in the docs where it has:

${bool:ifElse('a','b')}

Which evaluates to 'a' when the value of bool is "true".

In your case the value of sql.args.3.value is 't' or 'f' so it needs an operation to be applied which results in "true" or "false", such as what you did with the equals('t') comparison.