Search code examples
sqlpostgresqldate-arithmetic

Compare date and seconds to timestamp


I have a Postgres table that stores created timestamp in a created_date DATE column and a created_time INT column holding seconds since midnight.

EDIT: The table is on a customer's production db and stores data from an older system, its not possible to make schema changes.

I would like to make a selection based on created timestamp.

In MySQL I would write:

SELECT * FROM MyCustomers
WHERE ADDTIME(created_date,SEC_TO_TIME(created_time)) > 'sometimestampliteral'

How would that look in PostgreSQL?

I can see examples in the manual, but they are all using literal values and not values from table columns.


Solution

  • Just add the two together:

    created_date + created_time * interval '1 second' > ?