Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeORM array is not supported in postgres?

I have a column kid_ages which is Integer[]. When migrating, I get the following error:

DataTypeNotSupportedError: Data type "Array" in "home.kid_ages" is not supported by "postgres" database.

I tried adding the following options to my column:

type: 'array' 

and:

array: true, default: [], nullable: false,  @Column({   array: true,   default: [],   nullable: false, }) kid_ages: string; 
like image 816
ben berizovsky Avatar asked Aug 22 '19 14:08

ben berizovsky


2 Answers

The docs says, that it should work:

@Column("int", { array: true }) array: number[]; 

this is from the example https://github.com/typeorm/typeorm/blob/master/test/functional/database-schema/column-types/postgres/entity/Post.ts

In your code the array property is no array. Have you tried kid_ages: string[];?

like image 95
thopaw Avatar answered Sep 22 '22 09:09

thopaw


As mentioned above, you can create Postgres' array column with next code:

@Column("int", { array: true }) kid_ages: number[]; 

If you then need to find some kid with age 5, use this:

kid = getRepository('kid')         .createQueryBuilder()         .where(':kid_age = ANY (kid.kid_ages)', { kid_age: 5 }); 
like image 32
Dmitriy Apollonin Avatar answered Sep 23 '22 09:09

Dmitriy Apollonin