You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EQL supports a subset of functionality supported by the native Postgres JSON(B) functions and operators. The following examples compare natiive Postres JSON(B) functions and operators to the related functionality in EQL.
3
+
EQL supports a subset of functionality supported by the native Postgres JSON(B) functions and operators. The following examples compare native Postres JSON(B) functions and operators to the related functionality in EQL.
EQL JSONB functions accept an eJSONPath as an argument (instead of using `->`/`->>`) for lookups.
317
+
318
+
#### Decryption example
319
+
320
+
EQL currently doesn't support returning a specific array element for decryption, but `cs_ste_vec_value_v1` can be used to return an array to the client to process.
321
+
322
+
The query...
323
+
324
+
```sql
325
+
SELECT cs_ste_vec_value_v1(encrypted_jsonb, $1) AS val FROM examples;
326
+
```
327
+
328
+
With the params...
329
+
330
+
```javascript
331
+
// Assume that examples.encrypted_jsonb has JSON objects with
332
+
// the shape:
333
+
{
334
+
"field_a": [1, 2, 3]
335
+
}
336
+
337
+
// `$1` is the EQL plaintext payload for the eJSONPath `$.field_a`:
338
+
{
339
+
"k":"pt",
340
+
"p":"$.field_a",
341
+
"i": {
342
+
"t":"examples",
343
+
"c":"encrypted_jsonb"
344
+
},
345
+
"v":1,
346
+
"q":"ejson_path"
347
+
}
348
+
```
349
+
350
+
Would return the EQL plaintext payload with an array (`[1, 2, 3]` for example):
351
+
352
+
```javascript
353
+
// Example result for a single row
354
+
{
355
+
"k":"pt",
356
+
"p":"[1, 2, 3]",
357
+
"i": {
358
+
"t":"examples",
359
+
"c":"encrypted_jsonb"
360
+
},
361
+
"v":1,
362
+
"q":null
363
+
}
364
+
```
365
+
366
+
#### Comparison example
367
+
368
+
`cs_ste_vec_terms_v1` can be used with the native Postgres array access operator to get a term for comparison by array index.
369
+
370
+
The eJSONPath used with `cs_ste_vec_terms_v1` needs to end with `[*]` (`$.some_array_field[*]` for example).
371
+
372
+
> [!IMPORTANT]
373
+
> Array access with `cs_ste_vec_terms_v1` only works when the given eJSONPath only matches a single array.
374
+
> Accessing array elements from `cs_ste_vec_terms_v1` when the eJSONPath matches multiple arrays (for example, when there are nested arrays or multiple arrays at the same depth) can return unexpected results.
375
+
376
+
The following query compares the first item in the array at the eJSONPath in $1 to the value in $2.
377
+
378
+
```sql
379
+
SELECT*FROM examples
380
+
WHERE (cs_ste_vec_terms_v1(examples.encrypted_jsonb, $1))[1] > cs_ste_vec_term_v1($2)
381
+
```
382
+
383
+
```javascript
384
+
// Assume that examples.encrypted_jsonb has JSON objects with
385
+
// the shape:
386
+
{
387
+
"field_a": [4, 5, 6]
388
+
}
389
+
390
+
// `$1` is the EQL plaintext payload for the eJSONPath `$.field_a[*]`:
391
+
{
392
+
"k":"pt",
393
+
"p":"$.field_a[*]",
394
+
"i": {
395
+
"t":"examples",
396
+
"c":"encrypted_jsonb"
397
+
},
398
+
"v":1,
399
+
"q":"ejson_path"
400
+
}
401
+
402
+
// `$2` is the EQL plaintext payload for the ORE term to compare against (in this case, the ORE term for the integer `3`):
0 commit comments