I have several tables with inheritance:

  1. product
  2. smartphone
  3. tablet

Tables smartphone and tablet are inherited from the product .
Suppose I added an entry to the smartphone table, but then I want to transfer this entry to the tablet table. I need to keep all foreign keys, ID and field set. Is it even possible?

  • Write a transfer procedure where you can transfer all the necessary data. - Akina

1 answer 1

It turned out without any problems to move the record with the change of type from one table to another. If you do something like that, I recommend wrapping the construct into a transaction.

 with deleted as ( delete from only product.tablet where id=12923 returning * ) insert into product.smartphone (id, created_at, updated_at, name, type, brand_id, additional_data, link) select id, created_at, updated_at, name, 'smartphone', brand_id, additional_data, link from deleted;