Home > Enterprise >  How to insert values into an already existing table in postgresql?
How to insert values into an already existing table in postgresql?

Time:02-23

I have an already existing table in postgresql called order_facts.

Running select * from order_facts gets you this: as you can see order_date is null and I'd like to populate it with data from another table. To do that i used the following code:

insert into order_facts(order_date)
select day_key
from "Day" as d, orders as o
where d.fulldate = o.order_date;

But this appends the day_key values at the bottom of the table like so What do I change in my insert command to get it to start inserting the day_key from row 1 and not the end of the row?

CodePudding user response:

You need to use UPDATE instead of INSERT.

e.g.

update order_facts
set order_date = d.day_key
from "Day" as d, orders as o
where d.fulldate = o.order_date
and order_facts.order_id = o.order_id
  • Related