Home > Back-end >  EXTRACT returns numeric instead double precision
EXTRACT returns numeric instead double precision

Time:05-25

I ran into a problem: on a local database, EXTRACT returns numeric, which causes an error because the backend cannot parse it to int. On the production database everything works well and returns double precision as it should. In the sql, everything is of type timestamp without time zone. With what such behavior can be connected? Some local setting?

select EXTRACT(EPOCH FROM (finish_timestamp_p - answer_timestamp_p)) AS duration from ...

enter image description here

CodePudding user response:

The return type of EXTRACT changed from double precision to numeric in PostgreSQL v14.

I can think of two solutions:

  • add an explicit type cast:

    CAST (EXTRACT (....) AS integer)
    
  • use date_part instead of EXTRACT, which still returns double precision

  • Related