Skip to content

Deparse error with ON CONFLICT DO NOTHING #128

@ChrisJohnNewton

Description

@ChrisJohnNewton

I received this error stack trace while deparsing the following SQL:

INSERT INTO
  public.people (id, name, epithet, is_great, gender, type_id, date_of_birth, date_of_death, place_of_birth, place_of_death, biography, canonical_status_id, image_url, source_url)
VALUES
  (1, 'Asterius', 'of Amasea', FALSE, 'M', 1, '0350-01-01', '0410-01-01', 'Cappadocia', 'Amasea', NULL, 1, NULL, NULL),
  (2, 'Ausonius', NULL, FALSE, 'M', 1, '0310-01-01', '0395-01-01', 'Burdigala', NULL, NULL, NULL, NULL, NULL)
ON CONFLICT DO NOTHING;
/Users/chris/Documents/catholica/node_modules/pgsql-deparser/main/deparser.js:1231
            if (clause.infer.indexElems) {
                             ^

TypeError: Cannot read properties of undefined (reading 'indexElems')
    at Deparser.InsertStmt (/Users/chris/Documents/catholica/node_modules/pgsql-deparser/main/deparser.js:1231:30)
    at Deparser.deparse (/Users/chris/Documents/catholica/node_modules/pgsql-deparser/main/deparser.js:281:26)
    at Deparser.RawStmt (/Users/chris/Documents/catholica/node_modules/pgsql-deparser/main/deparser.js:285:25)
    at Deparser.deparse (/Users/chris/Documents/catholica/node_modules/pgsql-deparser/main/deparser.js:281:26)
    at /Users/chris/Documents/catholica/node_modules/pgsql-deparser/main/deparser.js:161:33
    at Array.map (<anonymous>)
    at Deparser.deparseQuery (/Users/chris/Documents/catholica/node_modules/pgsql-deparser/main/deparser.js:161:14)
    at deparse (/Users/chris/Documents/catholica/node_modules/pgsql-deparser/main/deparser.js:146:42)
    at file:///Users/chris/Documents/catholica/database/seeders/seed.js:28:19

Line 1231
image

It doesn't seem to like the ON CONFLICT DO NOTHING and clause has no infer property. I've fixed it locally with an optional chain after infer for both the if (line 1231) and else if (line 1236).
image

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