Answer the question
In order to leave comments, you need to log in
JPA + partitions in PostgreSQL. How to implement an insert only in a partition?
There is a table TABLE in PostgreSQL which has n partitions (TABLE_1, TABLE_2, ..., TABLE_n). There is a trigger that, when inserted into a TABLE table, inserts data into a partition. Trigger:
IF (NEW.program_id=1) THEN INSERT INTO st.table_1 VALUES (NEW.*);
ELSIF (NEW.program_id=2) THEN INSERT INTO st.table_2 VALUES (NEW.*);
....
return NEW;
@Entity
@Table(name = "TABLE", schema = "st")
public class TABLE implements Serializable {
@Getter
@Setter
@Column(name = "id", nullable = false, insertable = false, columnDefinition = "integer auto_increment")
private Integer id;
@Getter
@Setter
@Column(name = "program_id", nullable = false)
private Integer programId;
.... }
public interface TableRepository extends JpaRepository<TABLE, Integer> {}
TableRepository.save(myTable);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question