4

I would like to store an array of strings in my Postgres database, I have the below code but it is not working as I want:

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

I got the following error:

PostgreSQL said: malformed array literal: "["james"]"
Detail: "[" must introduce explicitly-specified array dimensions.

Anything I might be doing wrong?

2 Answers 2

14

I was able to resolve this with

  @Column('simple-array', { nullable: true, array: true })
  city: string[];
Sign up to request clarification or add additional context in comments.

1 Comment

In my case TypeORM saved string as "{"a", "b", "c"}" and could not parse it properly when fetched from DB. What helped was adding array: true to column definition: @Column({type: "simple-array", array: true})
3

This should work for an array.

@Column('text', { array: true })
names: string[];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.