I need to create surrogate key and add it as a new column to the tables My case is :
Table1:
| Product_ID | Product_Unique_ID | NEW COLUMN with surrogate key |
|---|---|---|
| 123 | 123-aaa | 123-123-aaaa |
| 123 | 123-bbb | 123-123-bbb |
| 456 | null | 456 |
| 789 | 789-aaa | 789-789-aaaa |
contrain is that in Table2 I have only Product_Id without Product Unique ID so how can i create surrogate key for it? if for case 123 there are 2 unique ids ?
First, for each
Product_IDonesurrogate keyis to be set. One method is to group table1 byProduct_IDand use an aggregation for thesurrogate key. This can beany_value,min,maxor evenarray_agg.