Dynamically select dbname for PostgreSQL query

Hi. I have a PostgreSQL instance running on an EC2 with hundreds of databases, each one belonging to a unique user with a unique dbname. I do not want to create a different Retool resource for each one. The functionality I am going for is that on the Retool UI, I input a dbname and my query runs on a specific table of the database for that dbname. Is there any way for me to run a query that allows me to dynamically select which dbname to hook into? Alternatively, could I create a javascript query that inserts the dbname dynamically? I am not sure how to do this if I am unable to import any javscript packages. Any feedback would be much appreciated!