Postgres update several tables



  • There is a structure.

    введите сюда описание изображения

    I want to change at the same time. elem_id Table data Table header_has_elem based on sample in the table header Field type



  • PostgreSQL has long-standing constructions with which new values can be reverted as a table. And no scumbags with stores for such a small task.

    The code may have to be adapted to this task, because it is likely that I did not correctly understand the author, but it shows how to use the task and achieve the desired effect of only minor changes.

    with new_data as (
      update data
      set elem_id = %new_value%
      where header_id = %header_id%
      returning *
    )
    update header_has_elem
    set elem_id = (select d.elem_id from new_data d where d.header_id = header_id limit 1)
    where id in (select a.id from analiz a join new_data d on d.header_id = a.header_id)
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2