examples for strings
@@ -3,29 +3,36 @@ use pgx::*;
pg_module_magic!();
#[pg_extern]
-fn hello_strings() -> &'static str {
- "Hello, strings"
+fn return_static() -> &'static str {
+ "This is a static string"
}
-#[cfg(any(test, feature = "pg_test"))]
-mod tests {
- use pgx::*;
-
- #[pg_test]
- fn test_hello_strings() {
- assert_eq!("Hello, strings", crate::hello_strings());
+#[pg_extern]
+fn to_lowercase(input: &str) -> String {
+ input.to_lowercase()
}
+#[pg_extern]
+fn substring(input: &str, start: i32, end: i32) -> &str {
+ &input[start as usize..end as usize]
}
-#[cfg(test)]
-pub mod pg_test {
- pub fn setup(_options: Vec<&str>) {
- // perform one-off initialization when the pg_test framework starts
+#[pg_extern]
+fn append(mut input: String, extra: &str) -> String {
+ input.push_str(extra);
+ input.push('x');
+ input
}
- pub fn postgresql_conf_options() -> Vec<&'static str> {
- // return any postgresql.conf settings that are required for your tests
- vec![]
+#[pg_extern]
+fn split(input: &'static str, pattern: &str) -> Vec<&'static str> {
+ input.split_terminator(pattern).into_iter().collect()
}
+
+#[pg_extern]
+fn split_set(
+ input: &'static str,
+ pattern: &'static str,
+) -> impl std::iter::Iterator<Item = &'static str> {
+ input.split_terminator(pattern).into_iter()
}
