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

Function register_array_upper

src/functions/array_functions.rs:77–107  ·  view source on GitHub ↗

array_upper(array, dimension) - Get upper bound of array dimension

(conn: &Connection)

Source from the content-addressed store, hash-verified

75
76/// array_upper(array, dimension) - Get upper bound of array dimension
77fn register_array_upper(conn: &Connection) -> Result<()> {
78 conn.create_scalar_function(
79 "array_upper",
80 2,
81 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
82 |ctx| {
83 let array_json: String = ctx.get(0)?;
84 let dimension: i32 = ctx.get(1)?;
85
86 match serde_json::from_str::<JsonValue>(&array_json) {
87 Ok(JsonValue::Array(arr)) => {
88 if dimension == 1 {
89 Ok(Some(arr.len() as i32))
90 } else if dimension == 2 {
91 // For 2D arrays, check first element
92 if let Some(JsonValue::Array(inner)) = arr.first() {
93 Ok(Some(inner.len() as i32))
94 } else {
95 Ok(None)
96 }
97 } else {
98 Ok(None)
99 }
100 }
101 _ => Ok(None),
102 }
103 },
104 )?;
105
106 Ok(())
107}
108
109/// array_lower(array, dimension) - Get lower bound (always 1 for PostgreSQL arrays)
110fn register_array_lower(conn: &Connection) -> Result<()> {

Callers 1

register_array_functionsFunction · 0.85

Calls 2

getMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected