How do you connect to specific Postgres schema using Sqlalchemy?
So I've created a new schema called "rezerwacja_domkow". I can see it in Pgadmin4. But the whole schema system confuses me (so far I've played only with sqlite which was much more straightforward). I have no clue how to connect to it and work only in this schema.
When I connect to the main db I see:
List of schemas
Name | Owner
-------------------+-------------------
public | pg_database_owner
rezerwacja_domkow | postgres
tiger | postgres
tiger_data | postgres
topology | postgres
(5 rows)
But when I try to list table names using Sqlalchemy inspector I don't see any tables from "rezerwacja_domkow" schema. I'd like to "connect" to this specific schema and modify / add data only to this one. Your help is greatly appreaciated.
To connect to the specific schema you first need to create database URL. This can be done as:
The "currentSchema" property is referring to the schema selected.
Next, create engine:
Now, to execute query:
In the end close connection:
*Replace table names & credentials accordingly.
Reference-1: https://analyzingalpha.com/connect-postgresql-sqlalchemy
Reference-2: https://docs.sqlalchemy.org/en/20/core/engines.html