feathersjs / docs

[MOVED] Legacy Feathers documentation
https://crow.docs.feathersjs.com/
MIT License
242 stars 532 forks source link

PG for Postgres may give problems for top level arrays in JSONB columns #1576

Closed AshotN closed 11 months ago

AshotN commented 1 year ago

Comment/Problem

Whenever a schema contains a property of Type.Array(Type.Object()) with PostgreSQL the user may encounter an issue during insert/update. This is related to this issue with pg.

The issue is basically that the parser can't handle a top level array normally. I found the simplest solution is to make sure that the column is of type jsonb[] in the database.

In Knex this is acheived with table.specificType('my_json_array', 'jsonb ARRAY')

The error the user may see if the column is jsonb is something like this

{
  "name": "NotFound",
  "message": "insert into \"my_json_array\") values ($1) returning \"id\" - invalid input syntax for type json",
  "code": 404,
  "className": "not-found"
}

System configuration

"@feathersjs/knex": "^5.0.0-pre.32",
"@feathersjs/schema": "^5.0.0-pre.32",
"@feathersjs/typebox": "^5.0.0-pre.32",
"pg": "^8.8.0"