Skip to content

Commit be458de

Browse files
Plain comparison only works with primitives
Comparing with an array will result in an error. I tried to see if I could implement comparison with an array, but that doesn't seem possible as you need to know the array type in postgres, which we don't.
1 parent bbadf91 commit be458de

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

filter/converter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ func (c *Converter) convertFilter(filter map[string]any, paramIndex int) (string
167167
}
168168
conditions = append(conditions, innerResult)
169169
default:
170+
if !isScalar(value) {
171+
return "", nil, fmt.Errorf("invalid comparison value (must be a primitive): %v", value)
172+
}
170173
conditions = append(conditions, fmt.Sprintf("(%s = $%d)", c.columnName(key), paramIndex))
171174
paramIndex++
172175
values = append(values, value)

filter/converter_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ func TestConverter_Convert(t *testing.T) {
208208
nil,
209209
fmt.Errorf("empty objects not allowed"),
210210
},
211+
{
212+
"compare with array",
213+
nil,
214+
`{"items": [200, 300]}`,
215+
``,
216+
nil,
217+
fmt.Errorf("invalid comparison value (must be a primitive): [200 300]"),
218+
},
211219
}
212220

213221
for _, tt := range tests {

0 commit comments

Comments
 (0)