Postgresql
Python code to backup table in PostgreSQL
Create new database table that is a copy of another table. Useful when you want to test some changes to data and you are not sure and want to have a backup. Credentials are loaded from .env file.
pythonpostgresqlsqlpsycopg.env
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
Interactive recipe
You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.
In the below recipe, we assume that you have following variables available in your notebook:
- conn (type Connection)
Python code
# Python code will be here
Code explanation
- Check if there is an open connection.
- If not then open the connection.
- Try to copy and backup the table.
- If error occurs raise exception.
Postgresql cookbook
Code recipes from Postgresql cookbook.
- « Previous
- Update selected
- Next »
- Create table