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

SQL: toDate and toDateTime should get custom format #606

Closed
lvca opened this issue Nov 8, 2022 Discussed in #605 · 1 comment
Closed

SQL: toDate and toDateTime should get custom format #606

lvca opened this issue Nov 8, 2022 Discussed in #605 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Milestone

Comments

@lvca
Copy link
Contributor

lvca commented Nov 8, 2022

Discussed in #605

Originally posted by vic0824 November 8, 2022
The DATETIME type uses millisecond precision (I guess because underneath it uses the java.util.Date class).
I think it would be very useful to have a type that allows representing date-time values with microsecond precision (actually, if a change is done, it might as well support nanoseconds).
This is a feature supported by many databases, and having it in ArcadeDB would help in establishing ArcadeDB as a valid alternative for many use cases.
I'd like to try some workarounds to represent microseconds, I'm not sure which is better (or less bad):
1 - store the value as an ISO-8601 string representation with microseconds, e.g. '2011-12-03T10:15:30.388724'; I'm not sure if the db engine will know how to sort and compare values in this format, i.e. if it will know how to evaluate a WHERE clause containing "time1 < time2".
2 - use two fields to store the value: a DATETIME field that stores the datetime with a millisecond resolution, and a SHORT (smallest primitive that allows representing the maximum number of microseconds in a millisecond);
3 - use BigDecimal and design my own representation of a DateTime as a number of microseconds since 1/1/1970 00:00:00.000000

Comments and suggestions are welcome.

@lvca lvca added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 8, 2022
@lvca
Copy link
Contributor Author

lvca commented Nov 8, 2022

Currently the best way to have microseconds is to save it as a string, and work with the date format like you mentioned. I've checked our SQL methods to convert dates from strings and we improve the usage for .asDateTime() by supporting a custom format as an optional parameter.

So I just implemented it. Now you can do:

results = db.query("sql", "select dateAsString.asDate(\"yyyy-MM-dd'T'HH:mm:ss.SSSSSS\") as convert from TestConversion");

Where the content of dateAsString property is '2011-12-03T10:15:30.388724'.

This is already in the 22.11.1-SNAPSHOT and will be released this month in the official 22.11.1 release.

Commit: 14a1260

Updated docs: ArcadeData/arcadedb-docs@a2c21b8

@lvca lvca closed this as completed Nov 8, 2022
@lvca lvca added this to the 22.11.1 milestone Nov 8, 2022
@lvca lvca self-assigned this Nov 8, 2022
lvca added a commit to ArcadeData/arcadedb-docs that referenced this issue Nov 9, 2022
@lvca lvca changed the title Storing DateTime values with microsecond precision SQL: toDate and toDateTime should get custom format Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant