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

Add date function to get current date without time component #1937

Merged
merged 8 commits into from
Jul 8, 2024

Conversation

paulrutter
Copy link
Contributor

@paulrutter paulrutter commented Jun 18, 2024

  • Add CURDATE/CURRENT_DATE method to AlaSQL
  • Add test

This removed the need for:

DATE(YEAR(NOW()) + '-' + MONTH(NOW()) + '-' + DAY(NOW()))

Thank you for the time you are putting into AlaSQL!

@paulrutter paulrutter changed the title #1936 Add date function to get current date without time component Add date function to get current date without time component Jun 19, 2024
@paulrutter
Copy link
Contributor Author

@mathiasrw any feedback on this pr? Thanks!

@mathiasrw
Copy link
Member

Interesting, relevant and missing. Nice.

SELECT CURDATE();

looks good to me. I do feel like we should avoid none standard notation like SELECT CURRENT_DATE(); and instead support the widely use same notation as MySQL and MariaDB with SELECT CURRENT_DATE; where its not a function, but a constant.

Are you feeling the mojo to try to dive into that? Adding it to src/alasqlparser.jison should not be too complex, but I admit its a bit exotic if you have not worked with parsers before.

@paulrutter
Copy link
Contributor Author

paulrutter commented Jun 30, 2024

Isn't the function exactly what MySQL offers?
See https://www.w3schools.com/sql/func_mysql_curdate.asp and https://www.w3schools.com/sql/func_mysql_current_date.asp and https://www.techonthenet.com/mariadb/functions/current_date.php#:~:text=The%20CURRENT_DATE%20function%20will%20return,synonym%20for%20the%20CURDATE%20function.

I do see that most also support an alias as constant, although we don't offer this for other date functions except CURRENT_TIMESTAMP in alasql. The current approach would be in line with other AlaSQL date functions. Do you want me to look into using these aliases?

To the parser point, i'm not seeing the other date functions in there. Is that deliberate? Only CURRENT_TIMESTAMP is there, not NOW for example.

I can look into adding it to the parser though next week.

@paulrutter
Copy link
Contributor Author

paulrutter commented Jun 30, 2024

@mathiasrw I tried rebuilding the parser via npm run jison. but the resulting alasqlparser.js is completely different from what's in git right now. Should i use a different command?

I wouldn't expect changes against what's in git.
Also, when i run the tests after generating the parser again, a lot of tests fail due to the parser throwing errors.

I found #1903 (comment), will try that and update the package.json if that works.

- Add rebuild parser documentation
- Add CURDATE/CURRENT_DATE to parser definition
- Allow both with and without parenthesis
- Adjust test
@paulrutter
Copy link
Contributor Author

paulrutter commented Jun 30, 2024

@mathiasrw
Can you take a look at the changes made?
I also added a section to rebuild the parser and added both CURDATE as CURRENT_DATE.
It can be used with and without parenthesis.

It feels to me like other date functions should be added to the parser as well, as these are currently missing.
DATE/NOW/GETDATE/YEAR/MONTH for example.

@paulrutter
Copy link
Contributor Author

#1936

README.md Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
@mathiasrw mathiasrw changed the base branch from develop to merge-fix July 8, 2024 22:24
@mathiasrw mathiasrw merged commit 7785563 into AlaSQL:merge-fix Jul 8, 2024
10 checks passed
@mathiasrw mathiasrw mentioned this pull request Jul 8, 2024
mathiasrw pushed a commit that referenced this pull request Jul 8, 2024
* #1936 Add date function to get current date without time component
- Add CURDATE method to AlaSQL
- Add test

* #1936 Add date function to get current date without time component
- Support dateAsString option
- Extend tests

* #1936 Add date function to get current date without time component
- Add CURRENT_DATE alias
- Extend test

* - Fix running the parser in package.json
- Add rebuild parser documentation
- Add CURDATE/CURRENT_DATE to parser definition
- Allow both with and without parenthesis
- Adjust test

* - Use tabs

* - Use alias to prevent duplicate code for CURRENT_DATE

* - Update dependencies
@paulrutter paulrutter deleted the feature/add-curdate branch July 9, 2024 04:59
@paulrutter
Copy link
Contributor Author

Thanks for merging, can we expect a new release soon?
@mathiasrw

@mathiasrw
Copy link
Member

Released as part of v4.5.0

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

Successfully merging this pull request may close these issues.

2 participants