coalesce(r.wptitle, w.wptitle) wptitle,
coalesce(r.story, w.story ) story,
r.creator, r.created, r.updated,
- CASE WHEN r.image IS NULL THEN w.id ELSE r.id END id -- image id
+ CASE WHEN nullif(r.image, '{}') IS NOT NULL THEN r.id
+ WHEN nullif(w.image, '{}') IS NOT NULL THEN w.id END id -- image id
FROM word r
LEFT JOIN word w ON w.id = r.ref;