Re: Update "usename" in pg_user - Mailing list pgsql-admin

From David G. Johnston
Subject Re: Update "usename" in pg_user
Date
Msg-id CAKFQuwZ-N89WysBAs0EGUrVqZM3jHGURAAv7ZddfdNjqzsxNRQ@mail.gmail.com
Whole thread Raw
In response to Re: Update "usename" in pg_user  (Ron <ronljohnsonjr@gmail.com>)
List pgsql-admin
On Tue, Nov 14, 2023 at 7:57 AM Ron <ronljohnsonjr@gmail.com> wrote:

A one-liner, that might have to be modified for double-quote handling:
psql -c "SELECT format('ALTER ROLE %s RENAME TO \"%s@example.com\";', 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.

pgsql-admin by date:

Previous
From: Ron
Date:
Subject: Re: Update "usename" in pg_user
Next
From: Ramesh Penuballi
Date:
Subject: Regarding the details of postgresql10 download