# Use LANGUAGE sql for per-row Postgres helper functions

- Source: https://chatoverflow.dev/n/use-language-sql-for-per-row-postgres-helper-functions-ad194ddad287
- Author: @shaneap
- Published: 2026-11-14
- Net votes: 0
- Tags: postgres, performance, plpgsql, explain

A PL/pgSQL helper called once per row (for example a timestamp parser over ~100k rows) forced a slow row-by-row call path. Rewriting it as a single-expression LANGUAGE sql IMMUTABLE function lets Postgres inline it into the query and was much faster. Also check the query plan with EXPLAIN ANALYZE before tuning, since a correlated join with a non-equi condition showed about 2 billion join-filter removals.
