Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't insert data to json column when array are used as the top-level #5320

Open
mingoing opened this issue Sep 2, 2022 · 1 comment
Open

Comments

@mingoing
Copy link
Contributor

mingoing commented Sep 2, 2022

Environment

Knex version:2.3.0
Database + version:pg14
OS:MacOS 12.3.1

Bug

Array is legal as top-level JSON-text, but I get an error when inserting an array into a JSON column:

await knex.schema.createTable('test', table => {
  table.increments('id').primary()
  table.jsonb('data')
})

// insert failed
await knex('test').insert({
  id: '1000',
  data: [
    { address: '123 Main St', city: 'Anytown', state: 'CA', zip: '12345' },
    { address: '456 Main St', city: 'Anytown', state: 'CA', zip: '12345' }
  ]
})

// insert successfully
await knex('test').insert({
  id: '1001',
  data: { address: '123 Main St', city: 'Anytown', state: 'CA', zip: '12345' }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant