Skip to content

Commit bbccf83

Browse files
fix issue in get events by age
1 parent 0ce67f1 commit bbccf83

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

sql_utils/sql_utils.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ func BuildContainedInColumnIntRangeCondition(
222222
conditions *[]string,
223223
args *[]interface{},
224224
) (int, error) {
225-
226225
inputStr = strings.TrimSpace(inputStr)
227226
if inputStr == "" {
228227
return argIndex, nil
@@ -234,26 +233,46 @@ func BuildContainedInColumnIntRangeCondition(
234233
}
235234

236235
if len(parts) == 1 {
237-
// Single value: value BETWEEN minCol AND maxCol
236+
// Single value case
238237
val, err := strconv.Atoi(strings.TrimSpace(parts[0]))
239238
if err != nil {
240239
return argIndex, fmt.Errorf("invalid integer value: %s", parts[0])
241240
}
242-
condition := fmt.Sprintf("($%d BETWEEN %s AND %s)", argIndex, minCol, maxCol)
241+
242+
condition := fmt.Sprintf(
243+
"((%s IS NOT NULL OR %s IS NOT NULL) AND "+
244+
"(%s IS NULL OR %s <= $%d) AND "+
245+
"(%s IS NULL OR %s >= $%d))",
246+
minCol, maxCol,
247+
minCol, minCol, argIndex,
248+
maxCol, maxCol, argIndex,
249+
)
250+
243251
*conditions = append(*conditions, condition)
244252
*args = append(*args, val)
245253
argIndex++
246-
} else if len(parts) == 2 {
247-
// Two values: first >= minCol AND second <= maxCol
254+
255+
} else {
256+
// Two-value range containment
248257
val1, err := strconv.Atoi(strings.TrimSpace(parts[0]))
249258
if err != nil {
250259
return argIndex, fmt.Errorf("invalid integer value: %s", parts[0])
251260
}
261+
252262
val2, err := strconv.Atoi(strings.TrimSpace(parts[1]))
253263
if err != nil {
254264
return argIndex, fmt.Errorf("invalid integer value: %s", parts[1])
255265
}
256-
condition := fmt.Sprintf("(%s <= $%d AND %s >= $%d)", minCol, argIndex, maxCol, argIndex+1)
266+
267+
condition := fmt.Sprintf(
268+
"((%s IS NOT NULL OR %s IS NOT NULL) AND "+
269+
"(%s IS NULL OR %s <= $%d) AND "+
270+
"(%s IS NULL OR %s >= $%d))",
271+
minCol, maxCol,
272+
minCol, minCol, argIndex,
273+
maxCol, maxCol, argIndex+1,
274+
)
275+
257276
*conditions = append(*conditions, condition)
258277
*args = append(*args, val1, val2)
259278
argIndex += 2

0 commit comments

Comments
 (0)