spec icon indicating copy to clipboard operation
spec copied to clipboard

Support timestamp and time functions on SQL fliters

Open evankanderson opened this issue 3 years ago • 9 comments

Had a conversation today with a user who wanted to be able to apply a filter like the following:

SELECT * WHERE time < NOW() - "5 minutes"

It would be handy to have a timestamp type and a handful of time-related functions. Off the top of my head:

  • NOW()
  • ADD / SUBTRACT
  • MINUTE / HOUR / DAY / DAY_OF_WEEK / MONTH / YEAR
  • LESS-THAN / GREATER-THAN

evankanderson avatar Jul 12 '21 23:07 evankanderson

Perhaps abbreviations to SI standards will reduce i18n?

erikerikson avatar Jul 13 '21 18:07 erikerikson

I'd probably lean towards whatever is in the SQL-99 standard (or later equivalent); I picked those out of a SQL manpage, but this book seems to be freely available and cover the standard itself.

evankanderson avatar Jul 13 '21 20:07 evankanderson

It looks like the proper SQL way to write the first clause would be:

SELECT * WHERE time < CURRENT_TIMESTAMP() - INTERVAL '5' MINUTE

evankanderson avatar Jul 13 '21 20:07 evankanderson

That makes complete sense and I feel a little foolish in hindsight. Thank you for helping remind me of context! 😄

erikerikson avatar Jul 14 '21 00:07 erikerikson

INTERVAL '5' MINUTE is an interesting syntax. Seems like a reasonable thing to do. Someone want to submit a PR?

duglin avatar Jul 21 '21 17:07 duglin

This issue is stale because it has been open for 30 days with no activity. Mark as fresh by updating e.g., adding the comment /remove-lifecycle stale.

github-actions[bot] avatar Mar 12 '23 01:03 github-actions[bot]

@evankanderson or perhaps @Cali0707 - does Knative need/want this? Perhaps a PR??

duglin avatar Mar 20 '24 19:03 duglin

@duglin I can definitely see where this would be useful for Knative, I can work on thinking this through more and opening a PR but I won't get it done in time for the call this week - hopefully next week! Would you be able to assign this to me?

Cali0707 avatar Mar 21 '24 01:03 Cali0707

done and thanks

duglin avatar Mar 21 '24 11:03 duglin