Navigation Menu

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 support for parts of the date and time in the clause RANGE window functions [CORE5471] #5741

Open
firebird-automations opened this issue Jan 26, 2017 · 2 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @sim1984

Currently RANGE clause supports only numeric values for PRECEDING and FOLLOWING borders. However, if an expression in the ORDER BY clause is a type of TIMESTAMP is difficult to set any interval except for days.

Example 1. Interval - 3 days

select
  bydate,
  total,
  sum\(total\) over w as s\_3days
from sales
window w as \(order by bydate range between 3  preceding and current row\)

Example 2. Interval - 3 hours

select
  bydate,
  total,
  sum\(total\) over w as s\_3hours
from sales
window w as \(order by bydate range between 3 \* 1\.000 / 24 preceding and current row\)

The last example is not very beautiful. Oracle Database uses the following syntax for time slots.

INTERVAL <expr> {YEAR | MONTH | DAY | HOUR | MINUTE | SECOND}

In this case, the second example would look like this

select
  bydate,
  total,
  sum\(total\) over w as s\_3hours
from sales
window w as \(order by bydate range between interval 3 hour preceding and current row\)
@firebird-automations
Copy link
Collaborator Author

Modified by: Sean Leyne (seanleyne)

description: Currently RANGE clause supports only numeric values for PRECEDING and FOLLOWING borders. However, if an expression in the ORDER BY clause is a type of TIMESTAMP is difficult to set any interval except for days.

Example 1. Interval - 3 days

select
bydate,
total,
sum(total) over w as s_3days
from sales
window w as (order by bydate range between 3 preceding and current row)

Example 2. Interval - 3 hours

select
bydate,
total,
sum(total) over w as s_3hours
from sales
window w as (order by bydate range between 3 * 1.000 / 24 preceding and current row)

The last example is not very beautiful. Oracle Database uses the following syntax for time slots.

INTERVAL <expr> {YEAR | MONTH | DAY | HOUR | MINUTE | SECOND}

In this case, the second example would look like this

select
bydate,
total,
sum(total) over w as s_3hours
from sales
window w as (order by bydate range between interval 3 hour preceding and current row)

=>

Currently RANGE clause supports only numeric values for PRECEDING and FOLLOWING borders. However, if an expression in the ORDER BY clause is a type of TIMESTAMP is difficult to set any interval except for days.

Example 1. Interval - 3 days

select
  bydate,
  total,
  sum\(total\) over w as s\_3days
from sales
window w as \(order by bydate range between 3  preceding and current row\)

Example 2. Interval - 3 hours

select
  bydate,
  total,
  sum\(total\) over w as s\_3hours
from sales
window w as \(order by bydate range between 3 \* 1\.000 / 24 preceding and current row\)

The last example is not very beautiful. Oracle Database uses the following syntax for time slots.

INTERVAL <expr> {YEAR | MONTH | DAY | HOUR | MINUTE | SECOND}

In this case, the second example would look like this

select
  bydate,
  total,
  sum\(total\) over w as s\_3hours
from sales
window w as \(order by bydate range between interval 3 hour preceding and current row\) 

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

INTERVAL is a generic data type, it's not specific to the RANGE clause. IMO, it does not make sense to implement it just for that purpose, it should be a global feature.

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

No branches or pull requests

1 participant