I was looking for a way to format my sql in nvim directly.

I found a nice cli called pgFormatter

On mac you can install it with brew

brew install pgformatter

In my case I use a linux distrib based on ubuntu

sudo apt-get install libcgi-pm-perl
cd /tmp
export version=5.4
wget https://github.com/darold/pgFormatter/archive/refs/tags/v${version}.tar.gz
tar xzf v${version}.tar.gz
cd pgFormatter-${version}/
perl Makefile.PL
make && sudo make install

After that you can use a range and called the external cli pg_format with !

# called pg_format on the current line
# called pg_format on the visually select lines

In action