官术网_书友最值得收藏!

How it works

Accessing a PostgreSQL database using the psycopg2 library as we did involves the use of two classes from the library: connect and cursor. The connect class opens and manages a connection with the database server. From that connection object, we can create a cursor object. This cursor is used for reading and writing data using SQL statements.

In the first example, we used the cursor to insert nine records into the database.  Those records are not written to the database until the commit() method of the connection is called.  This executes the writes of all the rows to the database.

Reading data uses a similar model, except that we execute an SQL query (SELECT) using the cursor and iterate across the rows that were retrieved.  Since we are reading and not writing, there is no need to call commit() on the connection.

主站蜘蛛池模板: 怀宁县| 积石山| 郴州市| 堆龙德庆县| 锦屏县| 顺昌县| 长岛县| 满城县| 斗六市| 拉孜县| 新建县| 准格尔旗| 黔东| 湘潭县| 吴桥县| 美姑县| 分宜县| 宜城市| 柏乡县| 新丰县| 太仆寺旗| 同德县| 城固县| 全椒县| 兴化市| 上杭县| 六安市| 临颍县| 南京市| 武宣县| 理塘县| 碌曲县| 郯城县| 磴口县| 通州区| 库尔勒市| 奎屯市| 都江堰市| 望城县| 禹城市| 延长县|