How coalesce
determine the return data type of the attribute?
self.projects(
select={"priority": "COALESCE(bm_rank, sales_rank, created_at)",
},
order_by=["priority"])
Its changing my float filed to the unicode string. I want to get float field in priority.
bm_rank = models.FloatField("Bizman Rank", max_length=10, blank=True, null=True)
sales_rank = models.FloatField("Sales Rank", max_length=10, blank=True, null=True)
created_at = models.DateTimeField("Date Submitted", auto_now_add=True)
What you are essentialy trying is to coalesce columns of different data types. You haven't specified your actual DB engine, but I can imagine only two sensible outcomes of such operation:
Looks like in your case it's second option.
If you are trying to order by bm_rank
then by sales_rank
then by created_at
you actually can do it without coalescing at all using order_by, like:
self.projects(order_by=["bm_rank", "sales_rank", "created_at"])