小编Yur*_*nko的帖子

JPA并插入表的分区

我在PostgreSQL中有一个TABLE,其中有n个分区(TABLE_1,TABLE_2,...,TABLE_n).有一个触发器,当您插入表TABLE时,将数据插入分区.触发:

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;
Run Code Online (Sandbox Code Playgroud)

我有一个对象:

@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;

.... }
Run Code Online (Sandbox Code Playgroud)

我有一个JpaRepository:

public interface TableRepository extends JpaRepository<TABLE, Integer> {}
Run Code Online (Sandbox Code Playgroud)

所以,当我保存对象TABLE时:

TableRepository.save(myTable);
Run Code Online (Sandbox Code Playgroud)

记录重复...几个表中的一个记录表,分区中的第二个记录...

如何制作仅在分区中的记录?

UPD.

我的@SQLInsert示例

@SQLInsert(sql …
Run Code Online (Sandbox Code Playgroud)

java postgresql hibernate jpa partitioning

5
推荐指数
1
解决办法
1034
查看次数

如何通过 Doobie 以 JSONB 格式插入案例对象?

我使用 scala 2.13 和 doobie 0.12.1

例如,我有案例类

case class UserInfo(name: String, age: Int, hobbies: Vector[String])
Run Code Online (Sandbox Code Playgroud)

我想在列信息中插入用户信息作为 jsonb

sql"""
        INSERT INTO users(
            id,
            info
            created_at,
        ) values (
            ${id},
            ${userInfo},
            ${createdAt},
        )
      """.update.run.transact(t)
Run Code Online (Sandbox Code Playgroud)

在我的 DAO 中,我有隐式 val

implicit val JsonbMeta: Meta[Json] = Meta
.Advanced.other[PGobject]("jsonb")
.timap[Json](jsonStr => parser.parse(jsonStr.getValue).leftMap[Json](err => throw err).merge)(json => {
  val o = new PGobject
  o.setType("jsonb")
  o.setValue(json.noSpaces)
  o
})
Run Code Online (Sandbox Code Playgroud)

但我有编译异常

found   : ***.****.UserInfo
   [error]  required: doobie.syntax.SqlInterpolator.SingleFragment[_]; incompatible interpolation method sql
    [error]       sql"""
    [error]       ^
Run Code Online (Sandbox Code Playgroud)

postgresql scala jsonb doobie

3
推荐指数
1
解决办法
1987
查看次数

标签 统计

postgresql ×2

doobie ×1

hibernate ×1

java ×1

jpa ×1

jsonb ×1

partitioning ×1

scala ×1