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

Extract function for date/time #611

Open
vaijns opened this issue Dec 7, 2024 · 1 comment
Open

Extract function for date/time #611

vaijns opened this issue Dec 7, 2024 · 1 comment

Comments

@vaijns
Copy link
Contributor

vaijns commented Dec 7, 2024

Sometimes when getting a date from a database you might not care about the whole date but just a part of it.
For example, if you have a list of articles and want to give the user a filter option for the year in which the article released, you just care about the year.
At the moment you'd have to get the whole date and then in your application code extract the year from it. This isn't a big deal of course but in SQL you have the EXTRACT(YEAR FROM CURRENT_TIMESTAMP) function.

I think having this function in sqlpp would be useful.

Similarly to #610 there's multiple options for the design of such a function.

  • Instead of extract you could have multiple functions year_of(date), month_of(date), ... like the functions MySQL has (YEAR(date), MONTH(date), ...).
  • You could have a templated function extract<datepart::year_t>(date)
  • You could have a parameter for the datepart and have the template parameter deduced extract(datepart::year, date)

Due to the EXTRACT(datepart FROM date) function being standardized I strongly prefer the latter two.

-Jonas

@rbock
Copy link
Owner

rbock commented Dec 9, 2024

The extract(datepart::year, date variant sounds reasonable to me.

As in #610: If you want to implement this, please wait until the optional-no-dynamic branch is a bit more advanced and then add it there.

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