On Tue, Nov 14, 2023 at 7:57 AM Ron <ronljohnsonjr@xxxxxxxxx> wrote:
A one-liner, that might have to be modified for double-quote handling:
psql -c "SELECT format('ALTER ROLE %s RENAME TO \"%s@xxxxxxxxxxx\";', username, username) FROM pg_user WHERE username != 'postgres'\gexec"
The two username uses can be shrunk to one with appropriate use of %s modifiers that I don't remember off the top of my head.
Yeah, it's positional. I think (motivated individuals can check the docs) %1$s
It would be nice to have an hstore and/or json variant of format so one can use names instead of positions.
format('%greeting$s, my name is %name$s', jsonb_build_object('name', 'Dave', 'greeting', 'Yo!')))
David J.