2

I want to use array_agg() function with sequelize. How can I do that ? I have been used below code, but it doesn't work.

let statusTabs = await Parameters.findAll({
    where: {
        param_key: 't_status',
        param_name: ['Washing', 'Awaiting', 'Pending']
    },
    attributes: [
        sequelize.literal('array_agg(param_key)'),
        sequelize.fn('array_agg', sequelize.col('param_key'))
    ]
});

It is giving errors like below -

TypeError: Cannot read property 'fn' of undefined

TypeError: Cannot read property 'literal' of undefined

How can I get array_agg() to work ?

1
  • I got the issue. The issue was regarding sequelize instance. It was not getting the proper instance of it. Commented Apr 7, 2021 at 6:01

1 Answer 1

3

This worked for me

Zone.findAll({
  attributes: [[Sequelize.fn('array_agg', Sequelize.col('city')), 'zones']],
  where: { country: 'Canada' },
  group: ['country']
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.