Search code examples
postgresqlnestjstypeorm

QueryFailedError: malformed array literal: "[]" in typeORM


I'm trying to add a new row to a table in postgres using TypeORM, but receive the issue related to array literals. The problem occurs with a subscriptions field

Entity format:

export class User {
  @PrimaryColumn()
  userId: string;

  @Column("varchar")
  email: string;

  @Column("text", { array: true })
  userCookieIds: string[];

  @Column("varchar", { array: true })
  userLocalIds: string[]

  @Column("jsonb", { array: true })
  subscriptions: object[]  
}

The code of typeORM insert:

        user = new User()
        user.userId = uuidv4()
        user.email = ''
        user.userCookieIds = [userCookieId]
        user.subscriptions = []
        user.userLocalIds = []        
        await this.usersRepository.save(user)

I checked all similar questions on StackOverflow, but it didn't help :-(

Any help is highly appreciated


Solution

  • As mentioned here: TypeORM jsonb array column and here: https://github.com/typeorm/typeorm/issues/4674 I deleted an array: true from @Column specification. After I dropped the postgres table and recreated it from scratch, everything statred to work as expexted.