create or replace function factorial(n) as ( list_reduce( list_transform(range(1,n+1), x -> x::HUGEINT), (prod,n) -> prod * n) );