question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Save array of jsonb in Postgres

See original GitHub issue

Issue type:

[ ] question [x] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [x] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

Hi, I have this column

@Column('jsonb', { array: true })
arrayOfJson: {foo: string}[];

and this function

async test() {
  const baz = await this.bazRepository.create({
    arrayOfJson: [
      {foo: 'bar'}
    ]
  })
  this.bazRepository.save(baz)
}

The column is created correctly in the database but when I try to save it I am getting this error QueryFailedError: malformed array literal: "[{"foo":"bar"}]"

It was issued here #204. Am I doing something wrong?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

21reactions
suyashgulaticommented, Apr 22, 2020

@lukasfrana Removing array:true from options works for me perfectly.

@Column('jsonb')
tasks: Foo[];

where Foo is another interface with multiple keys. No problem with saving as well.

11reactions
elie222commented, Feb 16, 2020

But simple-json stores as a string rather than as jsonb?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with a JSONB Array of Objects in PostgreSQL
Open pgAdmin and create a database as desired. · Right-Click on the database name and choose Query Tool. · Run the snippet below...
Read more >
Storing JSON Array of Arrays in PostgreSql - Stack Overflow
First statement returns two rows, one for each array. select jsonb_array_elements(msg->'root') as el from js. Then returns each individual ...
Read more >
How to keep array fields in PostgreSQL jsonb
My question is: Is there a way to store PostgreSQL arrays faithfully in JSONB objects? postgresql · json · array.
Read more >
Documentation: 15: 8.14. JSON Types - PostgreSQL
The jsonb data type supports array-style subscripting expressions to extract and modify elements. Nested values can be indicated by chaining subscripting ...
Read more >
How to Query JSONB Array of Objects in PostgreSQL
The syntax for Inserting values in the database is as follows: INSERT INTO TABLE_NAME(col1, col2, col3) VALUES(val1, val2, val3);. It is now ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found