Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading