tcdi / plrust

A Rust procedural language handler for PostgreSQL
PostgreSQL License
1.12k stars 33 forks source link

Prepare v1.2.7 #398

Closed eeeebbbbrrrr closed 1 year ago

eeeebbbbrrrr commented 1 year ago

Welcome to PL/Rust v1.2.7. This is a small feature release that adds the ability to call user defined functions (UDFs) from a LANGUAGE plrust function.

As a contrived example, perhaps your database has a LANGUAGE sql function like:

CREATE OR REPLACE FUNCTION sum_array(a int[]) RETURNS int STRICT LANGUAGE sql AS $$ 
    SELECT sum(e) FROM unnest(a) e 
$$;

And you wish to call it from a PL/Rust function. Well, now you can!

CREATE OR REPLACE FUNCTION transform_array(a int[]) RETURNS int STRICT LANGUAGE plrust AS $$
    // add one to every element of `a`, the input argument array, collecting into a new Vec
    let a = a.into_iter().map(|e| e.unwrap_or(0) + 1).collect::<Vec<_>>();  

    // call the existing "sum_array(int[])" function to sum the values of `a`
    Ok(fn_call("sum_array", &[&Arg::Value(a)])?)
$$;

SELECT transform_array(ARRAY[1,2,3]);
transform_array 
-----------------
               9
(1 row)

PL/Rust's dynamic function call API is documented in the book.

Other than also upgrading the underlying pgrx dependency to v0.11.0, there have been no other changes to PL/Rust since v1.2.6.

This release took quite a bit longer than expected as we had a desire to upgrade it to work with Rust v1.73.0. Unfortunately, rustc v1.73.0 introduced a bug around custom lints and it took our team weeks to track this down and ultimately provide the Rust project a PR. Based on Rust's release schedule, that fix won't be released until v1.75.0.

A note on Postgres 16 support

Postgres 16 has added some "SIMD" code, and includes the compiler built-in header for SIMD support. This can cause compilation problems with pgrx if the host system has multiple clang versions installed. It's suggested a machine running PL/Rust only have one clang version and the matching llvm packages installed. It doesn't seem to matter which version, only that there's one.