Skip to content

Commit c76e918

Browse files
committed
Improved sql_date method
1 parent 0ba91ea commit c76e918

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/pgslice/helpers.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,16 @@ def sql_date(time, cast, add_cast = true)
103103
fmt = "%Y-%m-%d"
104104
end
105105
str = quote(time.strftime(fmt))
106-
add_cast ? "#{str}::#{cast}" : str
106+
if add_cast
107+
case cast
108+
when "date", "timestamptz"
109+
"#{str}::#{cast}"
110+
else
111+
abort "Invalid cast"
112+
end
113+
else
114+
str
115+
end
107116
end
108117

109118
def name_format(period)

0 commit comments

Comments
 (0)