简体   繁体   中英

Fix ERROR: "operator does not exist: timestamp without time zone > integer" error

Im trying to migrate queries from Google big query to postgresql, and Im getting this error

ERROR: operator does not exist: timestamp without time zone > integer

select *, DATE(_modification_time) as modification_date, 
       CASE WHEN t_start>0 THEN DATE(t_start) END as start_date, 
       CASE WHEN _creation_time>0 THEN DATE(_creation_time) END as creation_date, 
       CASE WHEN t_finish>0 THEN DATE(t_finish) END as finish_date, 
       'WMT' as source 
from public.set_list

You are trying to compare a timestamp value with an integer (0). This is not allowed in Postgres. Instead, you can turn the timestamp into an integer by using the extract function and getting the number of seconds since the start of the Unix epoch (1970-01-01 00:00:00), which is an integer, then compare that with the integer 0, like this:

select *, DATE(_modification_time) as modification_date, 
       CASE WHEN extract(EPOCH FROM t_start) > 0
            THEN DATE(t_start) END as start_date, 
       CASE WHEN extract(EPOCH FROM _creation_time) > 0
            THEN DATE(_creation_time) END as creation_date, 
       CASE WHEN extract(EPOCH FROM t_finish) > 0
            THEN DATE(t_finish) END as finish_date, 
       'WMT' as source 
from public.set_list

However, I doubt that this is what you want as it means you are comparing if any of those values t_start , _creation_time and t_finish is later than 1970-01-01 00:00:00. Perhaps you can share a bit more about what you are trying to accomplish here. This would help you get more focused answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM