Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 520
Pavel Shepelenko Avatar asked Oct 24 '25 13:10

Pavel Shepelenko


1 Answers

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.

like image 101
Pavel Shepelenko Avatar answered Oct 27 '25 02:10

Pavel Shepelenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!