Skip to content
Snippets Groups Projects
Unverified Commit ce00efce authored by john-metabase's avatar john-metabase Committed by GitHub
Browse files

Updates Postgres format-interval to accept decimal numbers (#30849)

parent abc97878
No related branches found
No related tags found
No related merge requests found
......@@ -240,7 +240,7 @@
;; I tried to write this with Malli but couldn't figure out how to make it work. See
;; https://metaboat.slack.com/archives/CKZEMT1MJ/p1676076592468909
[_fn [amount unit]]
{:pre [(int? amount)
{:pre [(number? amount)
(#{:millisecond :second :minute :hour :day :week :month :year} unit)]}
[(format "INTERVAL '%s %s'" (num amount) (name unit))])
......
......@@ -54,13 +54,14 @@
(deftest ^:parallel interval-test
(is (= ["INTERVAL '2 day'"]
(sql/format-expr [::postgres/interval 2 :day])))
(is (= ["INTERVAL '-2.5 year'"]
(sql/format-expr [::postgres/interval -2.5 :year])))
(are [amount unit msg] (thrown-with-msg?
AssertionError
msg
(sql/format-expr [::postgres/interval amount unit]))
2.0 :day #"\QAssert failed: (int? amount)\E"
"2" :day #"\QAssert failed: (int? amount)\E"
:day 2 #"\QAssert failed: (int? amount)\E"
"2" :day #"\QAssert failed: (number? amount)\E"
:day 2 #"\QAssert failed: (number? amount)\E"
2 "day" #"\QAssert failed: (#{:day :hour :week :second :month :year :millisecond :minute} unit)\E"
2 2 #"\QAssert failed: (#{:day :hour :week :second :month :year :millisecond :minute} unit)\E"
2 :can #"\QAssert failed: (#{:day :hour :week :second :month :year :millisecond :minute} unit)\E"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment