Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Sequelize bulk insert error with polygon column

I have the following model with a column of type polygon

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('p_zones', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      points: {
        type: Sequelize.GEOMETRY('POLYGON')
      },
    });
  },
  down: async (queryInterface) => {
    await queryInterface.dropTable('ZonePoints');
  }
};

And when I try to seed using sequelize-cli with the command npx sequelize-cli db:seed:all

const polygon = {
      type: 'Polygon',
      coordinates: [
        [
          [10, 10],
          [20, 10],
          [20, 20],
          [10, 20],
          [10, 10],
        ],
      ],
    };
 const data = [{ points: polygon }];
 await queryInterface.bulkInsert('p_zones', data);

I get the following error:

ERROR: Invalid value {
  type: 'Polygon',
  coordinates: [ [ [ 10, 10 ], [ 20, 10 ], [ 20, 20 ], [ 10, 20 ], [ 10, 10 ] ] ]
}

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This appears to be an open issue on github for Sequelize version 6. You could try what Americas suggests on GitHub, i.e.

await queryInterface.bulkInsert(
    'p_zones',
    data,
    {},
    { points: { type: Sequelize.GEOMETRY('POLYGON') } });

Although I must admit, when I executed the above against a postgres database, I got the following error:

Executing (default): INSERT INTO "p_zones" ("points") VALUES (GeomFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))'));
(node:18964) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: function geomfromtext(unknown) does not exist
    at Query.formatError ...

But hopefully that's just an error due to the particular version of PostGIS that I have.

As an aside, your insert works fine if it's a .bulkCreate statement rather than a .bulkInsert one. Unfortunately, I don't know how to execute a .bulkInsert without defining the entire model first. Things you could try:

  1. Construct a raw query and do the bulk insert that way.
  2. Try defining the model by accessing the sequelize object from queryInterface.sequelize, and then do a .bulkCreate, which shouldn't give you any errors.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!