Skip to content

Commit 9cebf64

Browse files
committed
Improved query for max_id (not an issue previously due to to_i) [skip ci]
1 parent 0c8a08f commit 9cebf64

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/pgslice/table.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ def column_cast(column)
9696
def max_id(primary_key, below: nil, where: nil)
9797
query = "SELECT MAX(#{quote_ident(primary_key)}) FROM #{quote_table}"
9898
conditions = []
99-
conditions << "#{quote_ident(primary_key)} <= #{below}" if below
99+
params = []
100+
if below
101+
conditions << "#{quote_ident(primary_key)} <= $1"
102+
params << below
103+
end
100104
conditions << where if where
101105
query << " WHERE #{conditions.join(" AND ")}" if conditions.any?
102-
execute(query)[0]["max"].to_i
106+
execute(query, params)[0]["max"].to_i
103107
end
104108

105109
def min_id(primary_key, column, cast, starting_time, where)

0 commit comments

Comments
 (0)