Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use select and extract date into month and year from timestamp in sequelize ORM? #12032

Closed
5 tasks
wawasm opened this issue Mar 25, 2020 · 1 comment
Closed
5 tasks

Comments

@wawasm
Copy link

wawasm commented Mar 25, 2020

Issue Description

I have this query in sql:
select to_char (created_at,'Mon') as month, extract (year from created_at) as year, id_activity as activity from event group by 1, 2, 3

i tried to understand and make a simple sequelize query out of mysql query shown. I did something like this:
model.findAll({ attributes: [[ sequelize.fn('extract(year)', sequelize.col('created_at')), 'data']] });
however, it does not work.
i played around other aggregate function using 'sum', 'min', 'max'.. it does work.
how could i resolve this?..
thank you so much

StackOverflow / Slack attempts

https://stackoverflow.com/questions/60849911/how-to-use-select-and-extract-date-into-month-and-year-from-timestamp-in-sequeli

Additional context

Add any other context or screenshots about the issue here.

Issue Template Checklist

Is this issue dialect-specific?

  • No. This issue is relevant to Sequelize as a whole.
  • [/ ] Yes. This issue only applies to the following dialect(s): XXX, YYY, ZZZ
  • I don't know.

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • [/ ] Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
@sushantdhiman
Copy link
Contributor

Please use Github Issue Tracker only for reporting bugs, requesting new features or discussions. Ask questions on Stackoverflow sequelize.js tag or Slack. While I would like to help answer any questions but it still take too much time.

If you are reporting a bug please isolate it as SSCCE, present it nicely and follow issue template. This will help maintainers and contributors understand your issue quickly.

If you are requesting a feature spend some time to properly present your use case with some examples, current and expected outcome.

( What is SSCCE ? You can find template for Sequelize here )

A few good example of SSCCE

  1. ResourceRequest timed out - connection not reestablished after db restarted #8014 (comment)
  2. removeAttribute('id') results in undefined: null data value #7318 (comment)
  3. toJSON converting booleans to "t" (true) or "f" (false) #8749 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants