1

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?

1
  • 1
    use UPDATE instead of INSERT Commented Feb 22, 2022 at 22:13

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.