I want to combine two different tables.
table1
name | id | type | date |
---|---|---|---|
name1 | 1 | a | 08-17 |
name2 | 2 | b | 08-17 |
table2
name | id | date | attribute_1 |
---|---|---|---|
name1 | 1 | 08-18 | attr_id_1 |
name2 | 2 | 08-18 | attr_id_2 |
The two tables have in common "name" and "id" fields (used for mapping the records) and the field "date" is the partition key for both.
I need to carry out two operations:
- add a column in table1
- insert the records with "attribute_1" in table2
Expected Output:
name | id | type | date | attribute_1 |
---|---|---|---|---|
name1 | 1 | a | 08-17 | |
name2 | 2 | b | 08-17 | |
name1 | 1 | a | 08-18 | attr_id_1 |
name2 | 2 | b | 08-18 | attr_id_2 |
The inserted records should be in the new partition (new "date"). The "type" column in output table is duplicated from table1(actually there are other fields like "type" in table1 but for simplicity I just list one of them), it's like updating the rows in table1 with the "attribute_1" field, then insert the updated rows back into table1.
I've looked at the INSERT INTO
command in the official documentation but it seems that there is no such operation that does it all, what should I do?
Thanks in advance!