Skip to content
Advertisement

COALESCE(FIELD, “DEFAULT VALUE”) not working for postgresql + rails

Above is my raw sql query for my postgresql database. My problem is I want to display default file_path if it is null in the database. I tried three methods for this:

No Luck!, none of them works for me, and I don’t know why. What am I missing here?

[NOTE: please see this screenshot]

Advertisement

Answer

I’m pretty certain your problem is due to the left join, rather than the coalesce. If the left join yields no row, cover.file_path ends up null regardless of the coalesce or not.

Try moving the coalesce statement to a more appropriate location:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement