psycopg2 is a python module for PostgreSQL.
- Basic module usage
http://initd.org/psycopg/docs/usage.html#basic-module-usage
with
statement
Starting from version 2.5, psycopg2’s connections and cursors are context managers and can be used with the with
statement:
http://initd.org/psycopg/docs/usage.html#with-statement
- Server side cursors
http://initd.org/psycopg/docs/usage.html#server-side-cursors
When a database query is executed, the Psycopg cursor
usually fetches all the records returned by the backend, transferring them to the client process. If the query returned an huge amount of data, a proportionally large amount of memory will be allocated by the client.
If the dataset is too large to be practically handled on the client side, it is possible to create a server side cursor. Using this kind of cursor it is possible to transfer to the client only a controlled amount of data, so that a large dataset can be examined without keeping it entirely in memory.
Posts Referenced:
- http://support.datascientistworkbench.com/knowledgebase/articles/835206-access-postgresql-from-python-using-pscopg2
- Using psycopg2 with PostgreSQL https://wiki.postgresql.org/wiki/Using_psycopg2_with_PostgreSQL
- http://initd.org/psycopg/docs/cursor.html
- http://stackoverflow.com/questions/30427445/python-psycopg2-cursors
- PostgreSQL – Python Interface https://www.tutorialspoint.com/postgresql/postgresql_python.htm