Yes, it will have to. I need to tidy that up and move it to the model, possibly? Or if it's going to be a bit complex, should I create a plpgsql function?