Postgresql to Laravel eloquent

Someone please teach me how to use COALESCE and TO_CHAR in laravel DB:raw()

SELECT MAX(COALESCE(SUBSTR("COLUMN_CODE",8),'0')) AS MAX
FROM public."TABLE_ITEM"
WHERE COALESCE(TO_CHAR("START_DATE",'YYYYMM'),TO_CHAR("RECEIVED_DATE",'YYYYMM')) = '202104'

Tried using DB:raw but still got error

selectRaw("MAX(COALESCE(SUBSTR(COLUMN_CODE,8),0)) AS MAX")
->whereRaw("COALESCE(TO_CHAR("START_DATE",'YYYYMM'),TO_CHAR("RECEIVED_DATE",'YYYYMM')) = '202104'")


Read more here: https://stackoverflow.com/questions/66998231/postgresql-to-laravel-eloquent

Content Attribution

This content was originally published by pine at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: