0
select column_name::date, count(*) from table_name group by column_name::date

What is the equivalent of this SQL query in Sequelize? I couldn't find what to do when there is "double colon" in PostgreSQL query.

1
  • 2
    It's a type cast. In standard (ANSI) SQL it would be cast(column_name as date) Commented Mar 10, 2022 at 15:22

1 Answer 1

1

Thanks to a_horse_with_no_name comment I decide to use;

sequelize.literal("cast(time_column_name as date)")

with the grouping section and the latest code take form;

ModelName.findAndCountAll({
  attributes: [
    [sequelize.literal("cast(time_column_name as date)"), "time_column_name"],
  ],
  group: sequelize.literal("cast(time_column_name as date)"),
})

So, it gives two SQL query (because of findAndCountAll() function);

SELECT count(*) AS "count"
FROM "table_name"
GROUP BY cast(time_column_name as date);

AND

SELECT cast(time_column_name as date) AS "time_column_name"
FROM "table_name"
GROUP BY cast(time_column_name as date);
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.