B
B
bitwheeze2021-01-02 21:34:10
PostgreSQL
bitwheeze, 2021-01-02 21:34:10

How to subtract the calculated number of days from a date in Postgres?

In the plate, a certain hour is written in the tick field. I have added a new ts column to the table and want to update it based on the tick column. And something does not work in postgres to write UPDATE.

In a db2 database, update would look like this

update set ts = (current_timestamp - (tick * 10 / 60 / 60 / 24) days) .


In postgres, the manual says something like But I can't translate it to my task. Tried

set ts = current_timestamp - interval '10 day'


set ts = current_timestamp - interval cast(tick * 10 / 60 / 60 / 24 as string) || ' day'


But there are syntax errors.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bitwheeze, 2021-01-02
@bitwheeze

Found how.

set ts = current_timestamp - cast(tick * 10 / 60 / 60 / 24 as string) * interval '1 day'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question