Skip to content

[Postgres] JSON/B and arrays Question #183

Closed

Description

@dcworldwide

I've been experimenting with JSON/B support and have noticed the following:

With

@Column("json", { nullable: true })
myJsonField: any

The following persists:

myJsonField = {features: ["a", "b", "c"]}

but this doesn't:

myJsonField = ["a", "b", "c"]

persist throws 

 error: invalid input syntax for type json
[1]     at Connection.parseE (/Users/Danijel/projects/am/am-api/node_modules/pg/lib/connection.js:554:11)
[1]     at Connection.parseMessage (/Users/Danijel/projects/am/am-api/node_modules/pg/lib/connection.js:381:17)
[1]     at Socket.<anonymous> (/Users/Danijel/projects/am/am-api/node_modules/pg/lib/connection.js:117:22)
[1]     at emitOne (events.js:96:13)
[1]     at Socket.emit (events.js:188:7)
[1]     at readableAddChunk (_stream_readable.js:176:18)
[1]     at Socket.Readable.push (_stream_readable.js:134:10)
[1]     at TCP.onread (net.js:551:20)

According to the JSON spec, both examples are valid JSON. Should this work?

This is ultimately what i'm trying to achieve:

@Table()
export class BillingPlan extends Entity {

    @Column("json", { nullable: true })
    features: string[]
}

In this use case, storing features as a seperate table is overkill. Also using an @EmbeddedTable would also be overkill as I'm not storing properties in the embedded table, just a simple array.

What do you think? :)

Activity

  1. changed the title [-]Postgres JSON/B and arrays Question[/-] [+][Postgres] JSON/B and arrays Question[/+] on Jan 10, 2017
  2. dcworldwide commented on Jan 10, 2017

    @dcworldwide
    ContributorAuthor

    Note: There is a workaround, use @column("simple_array"). This solves my requirement, so will close.

  3. pleerock commented on Jan 10, 2017

    @pleerock
    Member

    Can you take a look if underlaying pg driver and postgres itself support storing array-json?

  4. xfoxfu commented on Jul 3, 2017

    @xfoxfu

    postgres support storing array-json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions