将字符串数组存储在 typeorm postgres 数据库中

dea*_*wap 4 sql postgresql typeorm

我想在 Postgres 数据库中存储一个字符串数组,我有以下代码,但它没有按我想要的方式工作:

  @Column({type: 'text', array: true, nullable: true })
  names: string[] = [];
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

PostgreSQL said: malformed array literal: "["james"]"
Detail: "[" must introduce explicitly-specified array dimensions.
Run Code Online (Sandbox Code Playgroud)

我可能做错了什么吗?

dea*_*wap 13

我能够解决这个问题

  @Column('simple-array', { nullable: true, array: true })
  city: string[];
Run Code Online (Sandbox Code Playgroud)

  • 在我的例子中,TypeORM 将字符串保存为“{”a”,“b”,“c”}”,并且从数据库获取时无法正确解析它。有用的是将 `array: true` 添加到列定义中: `@Column({type: "simple-array", array: true})` (4认同)