Support for semantic date queries
See original GitHub issueThe idea is that we add support for queries that look like this:
where: {
myDateTime: {
_semantic: {
value: "TODAY",
timezone: "+6:00"
}
}
}
Timezone could default to server time.
{
myDateTime: {
_semantic: {
value: "NEXT_N_DAYS",
n: 22
}
}
}
{
myDateTime: {
_semantic: {
value: "PAST_N_WEEKS",
timezone: "+6:00",
n: 3
}
}
}
{
myDateTime: {
_semantic: {
value: "LAST_MONTH",
timezone: "+6:00"
}
}
}
{
myDateTime: {
_semantic: {
value: "NEXT_N_HOURS",
timezone: "+6:00",
n: 3
}
}
}
These are inspired by the Salesforce API which calls them literals. See: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
The SQL can be implemented something like this:
Yesterday for example:
(
"myDateTimeField" >= (date_trunc('DAY', now() AT TIME ZONE '+6:00') - '1 DAY'::INTERVAL) AT TIME ZONE '+6:00' AND "myDateTimeField" < (date_trunc('DAY', now() AT TIME ZONE '+6:00')) AT TIME ZONE '+6:00'
)
Or parameterized:
pg.query(
"?? >= (date_trunc('DAY', now() AT TIME ZONE ?) - '1 DAY'::INTERVAL) AT TIME ZONE ? AND ?? < (date_trunc('DAY', now() AT TIME ZONE ?)) AT TIME ZONE ?",
[field, zone, zone, field, zone, zone]
)
I can collaborate to produce the SQL required for the other semantic dates that we want to support if this feature request has merit.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:40
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Help:Date parsing - semantic-mediawiki.org
Description: In order to select by date in inline queries it is necessary to specify dates with 2022, 12 etc separated by '-'...
Read more >Querying for date range in SPARQL - Stack Overflow
I'm trying to filter this list of objects down to one item by date; my query input is unfortunately only precise to the...
Read more >Semantic Graph Developer's Guide — Chapter 6
where hostname is the name of your MarkLogic Server host. From the Query Type drop-down list, select SPARQL Query. The Query Console supports...
Read more >Semantic date picker - CodePen
<link href="https://cdn.rawgit.com/mdehoog/Semantic-UI/6e6d051d47b598ebab05857545f242caf2b4b48c/dist/semantic.min.css" rel="stylesheet" type="text/css" />.
Read more >date_input: Define simple date input with Semantic UI styling
date_input( input_id, label = NULL, value = NULL, min = NULL, max = NULL, style = NULL, icon_name = "calendar" ) dateInput( inputId,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is there any movement on this? This would be an awesome addition!
Salesforce does it this way: “PAST_N_WEEKS:3” Which I didn’t like as much as having n outside the string because the client would have to build the string rather than just pass n as a variable.
I suppose you could put the timezone in as well: “PAST_N_WEEKS:3:+6:00” But now the timezone has a colon so you may want a different delimiter. “PAST_N_WEEKS,3,+6:00”
Looks impossible to validate.
OR
We could make them all keys:
or some combination with some string parsing
OR
Nesting with a required interval-type object
defaults to server timezone and _value of 1 maybe
The nested syntax would look great in graphiQL.
With the keys they could even be taken out of the _semantic namespace and be top level, but maybe too messy to have _gte and _yesterday on the same tier.