user12209184
user12209184

Reputation:

How to insert a date value stored in another table and increment it by x days?

I'm using a PostgreSQL database and have one table "event_date" with "started_at" (DATE format, e.g. '2019-10-29') values which are also the PRIMARY KEY in this table.

Now I want to insert this "started_at" value in another table "event_days" but increasing the date by x days.

Can someone explain how to achieve this? Thanks a lot!

Upvotes: 0

Views: 684

Answers (2)

ScaisEdge
ScaisEdge

Reputation: 133380

if you really need insert the related record you could use a insert select

insert into event_days(started_at, location , moderator)
select  started_at   + interval '10 day',  'hall 5' , 'Tom' 
from  event_date

Upvotes: 0

user330315
user330315

Reputation:

Use an INSERT with a SELECT:

insert into other_table (started_at, location, moderator)
select started_at + 42, 'Hall 5', 'Tom'
from event_days;

+ 42 add 42 days to the date value.

Upvotes: 1

Related Questions