Postgresql

Python code to create table in PostgreSQL

Create new database table ,credentials are loaded from .env file. Change table name, column identifiers, and data types. Number of columns needs to be equalt to number of data types

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

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

  1. Check if there is an open connection.
  2. If not then open the connection.
  3. Check if number of column is equal to data types.
  4. Try to create the table.
  5. If error occurs raise exception.

Example Python notebooks

Please find inspiration in example notebooks

« Previous
Backup table
Next »
Drop table