I was googling this question, but couldn't find anything that works.
I'm to tying to add a column to a table in postgres and then to populate the new column with data for the entire column (see example below)
original table orders:
order_id|order_date|order_time
--------+----------+----------
1|2015-01-01| 11:38:36
2|2015-01-01| 11:57:40
3|2015-01-01| 12:12:28
4|2015-01-01| 12:16:31
5|2015-01-01| 12:21:30
6|2015-01-01| 12:29:36
7|2015-01-01| 12:50:37
8|2015-01-01| 12:51:37
9|2015-01-01| 12:52:01
10|2015-01-01| 13:00:15
Say, I would like to make a column which is a timestamp by combining full_date.
this calls for: ALTER TABLE orders ADD COLUMN full_date timestamp;
Now, I would like to alter the original table by adding the data for the full_date column, so it would look like this:
order_id|order_date|order_time|full_date |
--------+----------+----------+-----------------------+
1|2015-01-01| 11:38:36|2015-01-01 11:38:36.000|
2|2015-01-01| 11:57:40|2015-01-01 11:57:40.000|
3|2015-01-01| 12:12:28|2015-01-01 12:12:28.000|
4|2015-01-01| 12:16:31|2015-01-01 12:16:31.000|
5|2015-01-01| 12:21:30|2015-01-01 12:21:30.000|
6|2015-01-01| 12:29:36|2015-01-01 12:29:36.000|
7|2015-01-01| 12:50:37|2015-01-01 12:50:37.000|
8|2015-01-01| 12:51:37|2015-01-01 12:51:37.000|
9|2015-01-01| 12:52:01|2015-01-01 12:52:01.000|
10|2015-01-01| 13:00:15|2015-01-01 13:00:15.000|
The only solution I managed to find, is by creating a new table from the orders table and then dropping the original table.
I tried INSERT INTO orders(full_date) SELECT order_date + order_time FROM orders
but it didn't work.
My question is, how do I populate the full_date data into the newly created column directly into the original orders table without creating a new table and then dropping the original.
Thank you in advance for any input!