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

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.

主站蜘蛛池模板: 平江县| 新昌县| 巧家县| 六盘水市| 兰溪市| 宽甸| 梅河口市| 金川县| 新沂市| 杭锦后旗| 屯留县| 广西| 孟州市| 馆陶县| 贵阳市| 观塘区| 邢台县| 尼木县| 海兴县| 望城县| 建始县| 普兰县| 汤阴县| 贵定县| 永州市| 筠连县| 双江| 娱乐| 台中市| 永善县| 历史| 尚志市| 六枝特区| 武功县| 乡城县| 汉源县| 鄱阳县| 长岛县| 鄂托克旗| 桂阳县| 灌云县|