As mentioned in the pg function document [here](https://pgpedia.info/l/lo_get.html), you could do it with the function `encode`:
SELECT encode(lo_get(12312), 'escape');