Postgresql
Python connect to PostgreSQL database
Open new Postgresql database connection, credentials are loaded from .env file. Incorrect credentials will raise an appropriate error. To edit the credentials add them in define new connection recipe.
pythonpostgresqlsqlpsycopg.envpython-dotenv
Required packages
You need below packages to use the code generated by recipe. All packages are automatically installed in MLJAR Studio.
psycopg>=3.2.1
python-dotenv>=1.0.1
Interactive recipe
You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.
Python code
# Python code will be here
Code explanation
- Load credentials from .env file.
- Try to establish connection with database.
- If checked, display the connection.
Example Python notebooks
Please find inspiration in example notebooks
- Backup table using python
- Connect to PostgreSQL database in Python
- Create new table using python and PostgreSQL
- From database to chart plotting
- Drop table using Python and PostgreSQL
- Fill PostgreSQL database with AI using Python
- Insert row into a table using Python
- Raw SQL query straight to pandas dataframe
- Run raw SQL query in python
- Select every column from table using python
- Show columns from table in PostgreSQL
- Show tables from PostgreSQL database
- Update column in table using Python
- Update selected rows of a column in table using python
- Transfer data from database to a Google sheet
Postgresql cookbook
Code recipes from Postgresql cookbook.
- « Previous
- Define a new connection
- Next »
- Show all tables