Postgresql

Python update selected columns in PostgreSQL

Update entire columns in database usign UPDATE PosgreSQL keyword. To gain finer control and update only selected rows use our raw query recipe and craft your own query! 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)
  • values (type list)
  • ids (type list)

Python code

# Python code will be here

Code explanation

  1. Check if there is an open connection.
  2. If not then open the connection.
  3. If update from list selected, pull data from given lists.
  4. Try to update the selection.
  5. If selected show results.
  6. If error occurs raise exception.
« Previous
Update column