Thursday, 1 June 2017

Sequelize query works with sqllite but not with mssql

I have the following sequelize function:

console.log(arr[index + 1], period, type, line, cell, site)
return db.History.findAll({
    where: {
        createdAt: {
            $lt: arr[index + 1],
            $gt: period
        },
        type: type,
        '$Line.name$': line
    },
    attributes: [[sequelize.fn('AVG', sequelize.col('value')), 'value']],
    include: [{
        model: db.Line,
        include: [{
            model: db.Cell,
            where: { name: cell },
            include: [{
                model: db.Site,
                where: { name: site }
            }]
        }]
    }]

In my Chai Unit tests, this db query executes as expected and returns the correct values, here is an example of the values logged out:

moment("2017-03-02T07:00:00.000") moment("2017-03-02T06:00:00.000") 'oee' '602' 'Powders' 'Ashford'
moment("2017-03-02T08:00:00.000") moment("2017-03-02T07:00:00.000") 'oee' '602' 'Powders' 'Ashford'
moment("2017-03-02T09:00:00.000") moment("2017-03-02T08:00:00.000") 'oee' '602' 'Powders' 'Ashford'
moment("2017-03-02T10:00:00.000") moment("2017-03-02T09:00:00.000") 'oee' '602' 'Powders' 'Ashford'
moment("2017-03-02T11:00:00.000") moment("2017-03-02T10:00:00.000") 'oee' '602' 'Powders' 'Ashford'
moment("2017-03-02T12:00:00.000") moment("2017-03-02T11:00:00.000") 'oee' '602' 'Powders' 'Ashford'

However, when I am testing this in "real life", I am getting the error:

RequestError: Column 'Histories.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

these are example of the queries logged out:

[1] moment("2017-06-01T01:00:00.000") moment("2017-06-01T00:00:00.000") 'oee' '604' 'powders' 'Ashford'
[1] moment("2017-06-01T02:00:00.000") moment("2017-06-01T01:00:00.000") 'oee' '604' 'powders' 'Ashford'
[1] moment("2017-06-01T03:00:00.000") moment("2017-06-01T02:00:00.000") 'oee' '604' 'powders' 'Ashford'
[1] moment("2017-06-01T04:00:00.000") moment("2017-06-01T03:00:00.000") 'oee' '604' 'powders' 'Ashford'
[1] moment("2017-06-01T05:00:00.000") moment("2017-06-01T04:00:00.000") 'oee' '604' 'powders' 

I can't see any difference between the parameters used in the unit tests and with the real life use. My unit tests use a sqllite db whereas the real life use, uses mssql aside from that I can't see any difference.

Any ide what is causing this?



via George Edwards

No comments:

Post a Comment