Reputation: 113
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.
Upvotes: 0
Views: 320
Reputation: 113
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);
Upvotes: 1