MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / position

Function position

src/expr/src/scalar/func.rs:2626–2641  ·  view source on GitHub ↗
(substring: &str, string: &str)

Source from the content-addressed store, hash-verified

2624
2625#[sqlfunc]
2626fn position(substring: &str, string: &str) -> Result<i32, EvalError> {
2627 let char_index = string.find(substring);
2628
2629 if let Some(char_index) = char_index {
2630 // find the index in char space
2631 let string_prefix = &string[0..char_index];
2632
2633 let num_prefix_chars = string_prefix.chars().count();
2634 let num_prefix_chars = i32::try_from(num_prefix_chars)
2635 .map_err(|_| EvalError::Int32OutOfRange(num_prefix_chars.to_string().into()))?;
2636
2637 Ok(num_prefix_chars + 1)
2638 } else {
2639 Ok(0)
2640 }
2641}
2642
2643#[sqlfunc]
2644fn strpos(string: &str, substring: &str) -> Result<i32, EvalError> {

Callers 1

strposFunction · 0.85

Calls 3

findMethod · 0.45
countMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected