Like @Adrian commented, normalize
is a reserved word in standard SQL. But it used to be allowed anyway until Postgres 13, where a system function of the same name was added. The release notes:
Add SQL functions NORMALIZE()
to normalize Unicode strings, and IS NORMALIZED
to check for normalization (Peter Eisentraut)
"normalize" changed its status to:
non-reserved (cannot be function or type)
While being at it, I suggest:
CREATE OR REPLACE FUNCTION f_normalize (input text, separator text DEFAULT '')
RETURNS text
LANGUAGE sql IMMUTABLE PARALLEL SAFE STRICT
BEGIN ATOMIC
SELECT lower(public.f_unaccent(translate(input, $$',:-`´‘’_$$, separator)));
END;
Most importantly, make it PARALLEL SAFE
(because it is) or you may regret it. See:
And STRICT
, since all used functions are strict themselves - assuming that for your f_unaccent()
.
BEGIN ATOMIC
requires Postgres 14 or later. (Else make it a conventional SQL function.) See:
Also, since translate()
is the cheapest operation, I would apply that first for a tiny overall gain.
Finally, if your f_unaccent()
function something like this, you might just add the additional operations into a single function instead of creating another wrapper.