Ash FrameworkAF
Ash Framework3y ago
54 replies
dblack

Concat with nil values

The built in concat calculation returns nil when any of the values it is concating is nil. I need a nil friendly concat and I could use something like this (which only works on the data layer and is postgres specific):

  calculate :full_name,
            :string,
            expr(fragment("concat_ws(?, ?, ?)", ", ", first_name, last_name))


I'd prefer to write a custom calculation that I can reuse (so the calculation can be run in Ash land after the record is retrieved from the db), but if I create a custom calculation (to use concat_ws) it is still only going to be suitable only for postgres datalayer. Is there a way that ash_postgres could use concat instead of || as an option?

I'm probably overthinking it and should just use the above calc and move on!
Was this page helpful?