Gurjeet Singh wrote:
All's okay, except you should not have declared it IMMUTABLE, because the results depend on a database query. From the docs: IMMUTABLE indicates that the function cannot modify the database and always returns the same result when given the same argument values; that is, it does not do database lookups or otherwise use information not directly present in its argument list
Yes, my bad. Make that STABLE. b ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match