Function to dynamically change postgres password

Solution 1:

Apart from the trivial syntax error of the superfluous =, you cannot use a parameter in an ALTER statement. You will have to use dynamic SQL:

EXECUTE format(
           'ALTER ROLE postgres PASSWORD %L',
           $1
        );

Let me add that changing a superuser's password from an application like that does not look like a sane security concept. You are not running your application with a database superuser, are you?