MCPcopy Create free account
hub / github.com/erans/pgsqlite / register_array_overlap

Function register_array_overlap

src/functions/array_functions.rs:423–447  ·  view source on GitHub ↗

array_overlap(array1, array2) - Check if arrays have common elements

(conn: &Connection)

Source from the content-addressed store, hash-verified

421
422/// array_overlap(array1, array2) - Check if arrays have common elements
423fn register_array_overlap(conn: &Connection) -> Result<()> {
424 conn.create_scalar_function(
425 "array_overlap",
426 2,
427 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
428 |ctx| {
429 let array1_json: String = ctx.get(0)?;
430 let array2_json: String = ctx.get(1)?;
431
432 match (
433 serde_json::from_str::<JsonValue>(&array1_json),
434 serde_json::from_str::<JsonValue>(&array2_json),
435 ) {
436 (Ok(JsonValue::Array(arr1)), Ok(JsonValue::Array(arr2))) => {
437 // Check if any element of arr1 is in arr2
438 let has_overlap = arr1.iter().any(|elem| arr2.contains(elem));
439 Ok(has_overlap)
440 }
441 _ => Ok(false),
442 }
443 },
444 )?;
445
446 Ok(())
447}
448
449/// array_slice(array, start, end) - Extract slice from array (1-based indexing)
450fn register_array_slice(conn: &Connection) -> Result<()> {

Callers 1

register_array_functionsFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected