PostgreSQL 9.6.17 COALESCE function error

coalescepostgresqlpostgresql-9.3postgresql-9.6type conversion

I'm trying a SQL query with the function COALESCE in PostgreSQL 9.6.17, but it produces an error:

invalid syntax for type double precision: ""

Example query:

SELECT COALESCE(date_part('year', s.date_pp),'')
FROM public.sendoc s.

This query is working on PostgreSQL 9.3.17.

How to get around the error at the server DB level without changing the source code of the program?

Best Answer

I don't think you can "fix" this without changing your query or going back to Postgres 9.3, where apparently type casting rules were more relaxed.

date_part() returns a floating point value, and in the absence of an implicit type cast Postgres tries to convert the other operand of coalesce() to a compatible value, and an empty string ('') cannot be so converted.