My first attempt was to encode the binary field as base64 and then edit it by using replace() or overlay(). The problem with this is that a project saved as qgz is zipped. This means that even if you encode it, you won't get the XML to change text passages. As a result you only damage the project file and the project can't be opened anymore.
My workaround now is a python script that changes the source URI of all postgres layers in the project at once and then writes the project back to the database. I didn't find a way to edit the projects directly on database level, but it would at least require the .qgz files to be unzipped.
One way to avoid this problem would be to store the projects as .qgs in the database, so the project files would be available as plain text and thus editable.