Postgresql
Python insert query in PostgreSQL
Execute sql insert query. Credentials are loaded from .env file. Choose table name, then list out columns you wish to fill and then their respectful values. Number of columns needs to be equal to number of values. You can ommit columns, if so None will be inserted.
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)
- values (type list)
- ids (type list)
Python code
# Python code will be here
Code explanation
- Check if there is an open connection.
- If not then open the connection.
- Check if number of column is equal to values.
- Try to insert into table.
- If checked show the results.
- If error occurs raise exception.
Example Python notebooks
Please find inspiration in example notebooks
Postgresql cookbook
Code recipes from Postgresql cookbook.
- « Previous
- Run select query
- Next »
- Update column