E
E
evgeniy20242022-02-20 20:26:20
PostgreSQL
evgeniy2024, 2022-02-20 20:26:20

How to change boolean value in db after certain time?

Hello everyone, I can’t figure out how to automatically change the value in the postgresql database, for example, change from true to false after 24 hours. I will be very grateful)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2022-02-20
@evgeniy2024

well, in general, there is a table with products and I planned to make such a functionality that will show information that this is a recently added product, and then automatically change its value after a certain time, well, the first thing that came to my mind was to do true, false)

Then the date of adding the product will be more than enough - then at the application level you can compare the current time and date of adding the product, and based on this, display this plate.
Well, either you can do something like this directly in the SQL query
SELECT id, (created_at > (current_timestamp - '1 day'::interval)) as "is_newly_added" FROM goods

S
Sergey Gornostaev, 2022-02-20
@sergey-gornostaev

99.99% sure you don't need it. For at least a hundred other users who have asked the same question here, it was solved in a different way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question