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

Function register_array_lower

src/functions/array_functions.rs:110–142  ·  view source on GitHub ↗

array_lower(array, dimension) - Get lower bound (always 1 for PostgreSQL arrays)

(conn: &Connection)

Source from the content-addressed store, hash-verified

108
109/// array_lower(array, dimension) - Get lower bound (always 1 for PostgreSQL arrays)
110fn register_array_lower(conn: &Connection) -> Result<()> {
111 conn.create_scalar_function(
112 "array_lower",
113 2,
114 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
115 |ctx| {
116 let array_json: String = ctx.get(0)?;
117 let dimension: i32 = ctx.get(1)?;
118
119 match serde_json::from_str::<JsonValue>(&array_json) {
120 Ok(JsonValue::Array(arr)) => {
121 if arr.is_empty() {
122 Ok(None)
123 } else if dimension == 1 {
124 Ok(Some(1))
125 } else if dimension == 2 {
126 // Check if it's actually a 2D array
127 if let Some(JsonValue::Array(_)) = arr.first() {
128 Ok(Some(1))
129 } else {
130 Ok(None)
131 }
132 } else {
133 Ok(None)
134 }
135 }
136 _ => Ok(None),
137 }
138 },
139 )?;
140
141 Ok(())
142}
143
144/// array_ndims(array) - Get number of dimensions
145fn register_array_ndims(conn: &Connection) -> Result<()> {

Callers 1

register_array_functionsFunction · 0.85

Calls 2

getMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected