The cursor class — Psycopg 2.9.3 documentation
www.psycopg.org › docs › cursorThe cursor class¶ class cursor¶. Allows Python code to execute PostgreSQL command in a database session. Cursors are created by the connection.cursor() method: they are bound to the connection for the entire lifetime and all the commands are executed in the context of the database session wrapped by the connection.
Basic module usage — Psycopg 2.9.3 documentation
www.psycopg.org › docs › usageconn = psycopg2. connect (DSN) with conn: with conn. cursor as curs: curs. execute (SQL1) with conn: with conn. cursor as curs: curs. execute (SQL2) conn. close () Warning Unlike file objects or other resources, exiting the connection’s with block doesn’t close the connection , but only the transaction associated to it.