0

I have two tables and I want to execute an update similar to this:

UPDATE table1 set table1.date = table2.date + table2.numberOfDays
FROM tabel2
WHERE table1.id = table2.table1_id

Edit: table1.date and table2.date is a date and table2.numberOfDays is a integer

  • 2
    Where is the problem (except that you have to write date instead of table1.date)? – Laurenz Albe Jul 12 at 12:33
  • 3
    set table1.date = table2.date + make_interval(days => table2.numberOfDays)? – Akina Jul 12 at 12:36
  • I edited the question by adding the types – Henrique Luiz Jul 12 at 13:05
  • 1
    That should work just fine (if you use set date = ... as Laurenz already mentioned). What exactly is the problem you have? – a_horse_with_no_name Jul 12 at 13:31
1

I found the following solution

UPDATE table1 set table1.date = (table2.date + (table2.numberOfDays || 'day')::INTERVAL)
FROM tabel2
WHERE table1.id = table2.table1_id

OR

UPDATE table1 set table1.date = table2.date + make_interval(days => table2.numberOfDays)
FROM tabel2
WHERE table1.id = table2.table1_id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.