B
B
Bogdan2019-08-20 17:01:34
Node.js
Bogdan, 2019-08-20 17:01:34

Sequelize numeric type returns as string?

I am using PostgreSQL. The SUM("Statistics"."quantityPrinted") AS "quantityPrinted" function returns a string value.

const response = await models.sequelize.query(
    `
    SELECT
      SUM("Statistics"."quantityPrinted") AS "quantityPrinted"
    FROM "Cartridges"
    left JOIN "Statistics" on "Statistics"."cartridgeId" = "Cartridges".id
    WHERE "Cartridges".id = 2
  `,
    { type: models.sequelize.QueryTypes.SELECT }
);

5d5bfca50b442990295256.jpeg
Changed settings, but only works for MySQL.
dialectOptions: {
    supportBigNumbers: true,
    bigNumberStrings: false
  }

PS Actually, I have a much more complicated query that cannot be built using ORM.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Bogdan, 2019-08-30
@bogdan_uman

Found a simple solution

const pg = require('pg');

// https://github.com/sequelize/sequelize/issues/4550
pg.defaults.parseInt8 = true;

V
vgbege, 2019-08-23
@vgbege

big numbers are expected there?
SELECT cast(SUM("Statistics"."quantityPrinted") as integer) AS "quantityPrinted" won't work?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question