The udfs command in ParadeDB lets you list, create, replace, and remove user-defined functions (UDFs) so they can be reused across SQL queries.
The udfs helper surfaces every user-defined function registered in your ParadeDB-backed PostgreSQL database. You can quickly audit available logic, check argument lists, and view return types without scanning pg_catalog tables.
Run SELECT * FROM paradedb.udfs();
. Each row shows schema
, function_name
, arg_types
, return_type
, and language
. Filtering by schema keeps noisy extensions out of view:
SELECT *
FROM paradedb.udfs()
WHERE schema = 'public';
The command is a wrapper around CREATE OR REPLACE FUNCTION
. Use it when you need logic reused in multiple queries, e.g., computing customer lifetime value (CLV).
function_name – unique identifier. arg_type – data type for each parameter. return_type – type of the value produced. LANGUAGE – e.g., SQL, plpgsql, plpython. VOLATILE, IMMUTABLE, or STABLE – planner hints. SECURITY DEFINER optionally elevates rights.
The function sums paid orders per customer.
CREATE OR REPLACE FUNCTION public.clv(p_customer_id INT)
RETURNS NUMERIC AS $$
SELECT COALESCE(SUM(total_amount), 0)
FROM Orders
WHERE customer_id = p_customer_id;
$$ LANGUAGE SQL IMMUTABLE;
-- Query using the UDF
SELECT c.id, c.name, clv(c.id) AS lifetime_value
FROM Customers AS c
ORDER BY lifetime_value DESC;
Because the UDF is IMMUTABLE
, ParadeDB can cache results during vector search pipelines to speed up ranking.
Use CREATE OR REPLACE FUNCTION
to patch logic without breaking dependent views. Run DROP FUNCTION IF EXISTS schema.fn_name(arg_types);
when the function is obsolete. Always include the argument list in the drop statement to avoid collisions.
IMMUTABLE
so ParadeDB’s query planner can inline them.analytics
) to prevent name clashes.COMMENT ON FUNCTION
so teammates understand usage.Forgetting argument types when dropping. Why it’s wrong: PostgreSQL treats each signature as unique. Fix: specify the full arg list.
Using VOLATILE for deterministic logic. Why it’s wrong: disables planner optimizations. Fix: mark as IMMUTABLE
or STABLE
.
Yes. Enable the plpythonu
language once per database: CREATE EXTENSION IF NOT EXISTS plpythonu;
. Then set LANGUAGE plpythonu
in your function.
Only if marked VOLATILE or doing heavy I/O. Pure calculations flagged IMMUTABLE are cached, so they rarely impact hybrid search latency.
Query the system catalog: SELECT objid::regprocedure, refobjid::regprocedure FROM pg_depend WHERE refobjid = 'public.clv(int)'::regprocedure;