'Can you run SET LOCAL with parameters in Typeorm / Postgres?

I have a database with row level security set, allowing me to automatically hide soft deleted data (deletedAt column set). I use SET LOCAL [schema].view_deleted=[TRUE/FALSE] to do this.

My database name is passed from a .env file and I'd like to parameterise it, but I just can't get it to work. It seems PG is blocking the parameterisation.

This is my method (runs within transactions):

disableViewDeletions() {
        return this.query(
            `EXECUTE format('SET LOCAL %s.view_deleted=FALSE', $1)`,
            [process.env.TYPEORM_DATABASE]
        );
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source