Skip to content
This repository was archived by the owner on Mar 25, 2022. It is now read-only.
This repository was archived by the owner on Mar 25, 2022. It is now read-only.

Empty arrays get serialised as empty string #3

@LinusU

Description

@LinusU

This causes a parse error in my sql query. Consider the following example:

CREATE TABLE thing(
  tags string[] NOT NULL
)
const format = require('pg-format')

format('INSERT INTO %I (%I) VALUES(%L)', 'thing', 'tags', [])

Now this get's formatted into the following query:

INSERT INTO thing (tags) VALUES()

Which gives the following error:

error: syntax error at or near ")"

I believe that the correct query output would have been:

INSERT INTO thing (tags) VALUES('{}')

A workaround is to send in the string '{}' to the format function, but that is very ugly and breaks my validation of data since it expects an array of strings...

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