0

I have a database table which has two date columns (i.e. from_date and to_date). The from_date column has data, but the to_date is null. I want to add dates in to_date column to be exactly 7 days later than the from_date. Is this possible in Postgres?

The link provided for the duplicate of my post is so sophisticated and provides a solution for wide range of problems. I found my answer in Google. All I needed was a simple update:

UPDATE records
SET to_datetime=from-datetime;
UPDATE records
SET to_datetime = to_datetime + interval '7 day';
Mike
  • 369
  • 5
  • 21
  • Create a view that returns that information, it's usually not necessary to store information that can easily be derived from existing data –  Mar 01 '19 at 17:48
  • I need the column to be present in the database – Mike Mar 01 '19 at 17:49
  • If you use a view it's "present" in the database as well. Do you plan to update the column to a different value at some time? –  Mar 01 '19 at 17:50
  • No. I plan to keep it as it is after I get the 7 days later data. I am using the table in a python django project which requires the column `to_date` to be there and be exactly 7 days later. For the sake of complication it could bring I am not able to change the python code for now. – Mike Mar 01 '19 at 17:53
  • you can still use a view for that. –  Mar 01 '19 at 17:54
  • I am kind of new to PSQL. Can you help me more on that? How exactly can I do this? – Mike Mar 01 '19 at 17:56
  • @a_horse_with_no_name thanks for your response. The post you provided for the duplicate of this post is very sophisticated. I am sure it does solve some related problems with a wider range, but I don't understand how it can help me. – Mike Mar 01 '19 at 19:29

0 Answers0