Skip to content

incorrect JSON generated for arrays passed in for columns of type json #374

Closed
@spollack

Description

@spollack

To repro:

  1. Using a postgres 9.2 database, create a table with a column of type json.
  2. Run an insert statement, passing in a javascript array as the parameter value for that column.
  3. pg generates an incorrect json string, and postgres errors with "invalid input syntax for type json".

For example, if my input array is:
["foo", "bar", "baz"]

The generated json string from pg is:
{"foo", "bar", "baz"}

In other words, the array gets wrapped with curly braces not square brackets.

You can see where this is happening in lib/utils.js. The issue is that we are trying to treat the array as a postgres array input, even though this should be treated as a json input because the database column is of type json.

I'd be happy to do a PR to fix this, but i'm not sure of the right strategy here -- it seems like to fix this problem, we need to know the column datatype, not just the input datatype? do we have that context available?

Thanks,
Seth

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions