The 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.

Cursors created from the same connection are not isolated, i.e., any changes done to the database by a cursor are immediately visible by the other cursors. Cursors created from different connections can or can not be isolated, depending on the connections’ isolation level. See also rollback() and commit() methods.

Cursors are not thread safe: a multithread application can create many cursors from the same connection and should use each cursor from a single thread. See Thread and process safety for details.

description

This read-only attribute is a sequence of 7-item sequences.

Each of these sequences is a named tuple (a regular tuple if collections.namedtuple() is not available) containing information describing one result column:

  1. name: the name of the column returned.
  2. type_code: the PostgreSQL OID of the column. You can use the pg_type system table to get more informations about the type. This is the value used by Psycopg to decide what Python type use to represent the value. See also Type casting of SQL types into Python objects.
  3. display_size: the actual length of the column in bytes. Obtaining this value is computationally intensive, so it is always None unless the PSYCOPG_DISPLAY_SIZE parameter is set at compile time. See also PQgetlength.
  4. internal_size: the size in bytes of the column associated to this column on the server. Set to a negative value for variable-size types See also PQfsize.
  5. precision: total number of significant digits in columns of type NUMERIC. None for other types.
  6. scale: count of decimal digits in the fractional part in columns of type NUMERIC. None for other types.
  7. null_ok: always None as not easy to retrieve from the libpq.

This attribute will be None for operations that do not return rows or if the cursor has not had an operation invoked via the execute*() methods yet.

Changed in version 2.4: if possible, columns descriptions are named tuple instead of regular tuples.

close()

Close the cursor now (rather than whenever del is executed). The cursor will be unusable from this point forward; an InterfaceError will be raised if any operation is attempted with the cursor.

closed

Read-only boolean attribute: specifies if the cursor is closed (True) or not (False).

DB API extension

The closed attribute is a Psycopg extension to the DB API 2.0.

New in version 2.0.7.

connection

Read-only attribute returning a reference to the connection object on which the cursor was created.

name

Read-only attribute containing the name of the cursor if it was creates as named cursor by connection.cursor(), or None if it is a client side cursor. See Server side cursors.

DB API extension

The name attribute is a Psycopg extension to the DB API 2.0.

Commands execution methods

execute(operation[, parameters])

Prepare and execute a database operation (query or command).

Parameters may be provided as sequence or mapping and will be bound to variables in the operation. Variables are specified either with positional (%s) or named (%(name)s) placeholders. See Passing parameters to SQL queries.

The method returns None. If a query was executed, the returned values can be retrieved using fetch*() methods.

executemany(operation, seq_of_parameters)

Prepare a database operation (query or command) and then execute it against all parameter tuples or mappings found in the sequence seq_of_parameters.

The function is mostly useful for commands that update the database: any result set returned by the query is discarded.

Parameters are bounded to the query using the same rules described in the execute() method.

callproc(procname[, parameters])

Call a stored database procedure with the given name. The sequence of parameters must contain one ll J4WMȇJ5uω@;t5SmlcR{Zmo]]COq̵ry,7+TRO'߇L{xZvzl,VN0a0W\1׸ir=) +S4=ܫ3Y ϗ4 sZ$h0Ej??@ߐw}6R}'ߍ͓ш.ǠU K7Vh+ҼQ4ЬFXoX/:nyCe"sMбiHAejN ¤`k 10t02xռ?.'46XXoRH.fn)Pn"?/xF=yQh55=Uf謯d @.HS$%Eu 3|0ظ*zT9YPQHP(8y-J+myASV'n>joq ˂dW- Pj$k3y et^%w2"4eJZ'eD@l@njS¸7}vdֱR'o _QV$HдC<6v&g!ΣRQVD.XʫfVgZ@؞Ӓ`n*0xCrYPsYi*DxhG&fA3Uh()"pVFؕT \A)\=3 %q|쵲,XrzMY0L{R7uBlhAOʹ.byu[Ikyof'tk Y̘JPkƄnx)M:ET譧](/*:sƮmR% #yhƆM!xA^ҝu(4Sց'kZ.׷0cnnÌZt. dT/]f?w1vRUK)Pfcb8.=?$#1pp0a [q+-ؿWfħʲY~ic\&>8 3^_~ȬϨ5/>CG%$+c_?~5 __Ua7 XnՕ|~}??ƒ{W~B߹d'^ɛ ~pΌc=q8vg&ߒkw/^dPc?c The cursor class — Psycopg v2.4.2 documentation

The 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.

Cursors created from the same connection are not isolated, i.e., any changes done to the database by a cursor are immediately visible by the other cursors. Cursors created from different connections can or can not be isolated, depending on the connections’ isolation level. See also rollback() and commit() methods.

Cursors are not thread safe: a multithread application can create many cursors from the same connection and should use each cursor from a single thread. See Thread and process safety for details.

description

This read-only attribute is a sequence of 7-item sequences.

Each of these sequences is a named tuple (a regular tuple if collections.namedtuple() is not available) containing information describing one result column:

  1. name: the name of the column returned.
  2. type_code: the PostgreSQL OID of the column. You can use the pg_type system table to get more informations about the type. This is the value used by Psycopg to decide what Python type use to represent the value. See also Type casting of SQL types into Python objects.
  3. display_size: the actual length of the column in bytes. Obtaining this value is computationally intensive, so it is always None unless the PSYCOPG_DISPLAY_SIZE parameter is set at compile time. See also PQgetlength.
  4. internal_size: the size in bytes of the column associated to this column on the server. Set to a negative value for variable-size types See also PQfsize.
  5. precision: total number of significant digits in columns of type NUMERIC. None for other types.
  6. scale: count of decimal digits in the fractional part in columns of type NUMERIC. None for other types.
  7. null_ok: always None as not easy to retrieve from the libpq.

This attribute will be None for operations that do not return rows or if the cursor has not had an operation invoked via the execute*() methods yet.

Changed in version 2.4: if possible, columns descriptions are named tuple instead of regular tuples.

close()

Close the cursor now (rather than whenever del is executed). The cursor will be unusable from this point forward; an InterfaceError will be raised if any operation is attempted with the cursor.

closed

Read-only boolean attribute: specifies if the cursor is closed (True) or not (False).

DB API extension

The closed attribute is a Psycopg extension to the DB API 2.0.

New in version 2.0.7.

connection

Read-only attribute returning a reference to the connection object on which the cursor was created.

name

Read-only attribute containing the name of the cursor if it was creates as named cursor by connection.cursor(), or None if it is a client side cursor. See Server side cursors.

DB API extension

The name attribute is a Psycopg extension to the DB API 2.0.

Commands execution methods

execute(operation[, parameters])

Prepare and execute a database operation (query or command).

Parameters may be provided as sequence or mapping and will be bound to variables in the operation. Variables are specified either with positional (%s) or named (%(name)s) placeholders. See Passing parameters to SQL queries.

The method returns None. If a query was executed, the returned values can be retrieved using fetch*() methods.

executemany(operation, seq_of_parameters)

Prepare a database operation (query or command) and then execute it against all parameter tuples or mappings found in the sequence seq_of_parameters.

The function is mostly useful for commands that update the database: any result set returned by the query is discarded.

Parameters are bounded to the query using the same rules described in the execute() method.

callproc(procname[, parameters])

Call a stored database procedure with the given name. The sequence of parameters must contain one ll J4WMȇJ5uω@;t5SmlcR{Zmo]]COq̵ry,7+TRO'߇L{xZvzl,VN0a0W\1׸ir=) +S4=ܫ3Y ϗ4 sZ$h0Ej??@ߐw}6R}'ߍ͓ш.ǠU K7Vh+ҼQ4ЬFXoX/:nyCe"sMбiHAejN ¤`k 10t02xռ?.'46XXoRH.fn)Pn"?/xF=yQh55=Uf謯d @.HS$%Eu 3|0ظ*zT9YPQHP(8y-J+myASV'n>joq ˂dW- Pj$k3y et^%w2"4eJZ'eD@l@njS¸7}vdֱR'o _QV$HдC<6v&g!ΣRQVD.XʫfVgZ@؞Ӓ`n*0xCrYPsYi*DxhG&fA3Uh()"pVFؕT \A)\=3 %q|쵲,XrzMY0L{R7uBlhAOʹ.byu[Ikyof'tk Y̘JPkƄnx)M:ET譧](/*:sƮmR% #yhƆM!xA^ҝu(4Sց'kZ.׷0cnnÌZt. dT/]f?w1vRUK)Pfcb8.=?$#1pp0a [q+-ؿWfħʲY~ic\&>8 3^_~ȬϨ5/>CG%$+c_?~5 __Ua7 XnՕ|~}??ƒ{W~B߹d'^ɛ ~pΌc=q8vg&ߒkw/^dPc?c The cursor class — Psycopg v2.4.2 documentation

The 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.

Cursors created from the same connection are not isolated, i.e., any changes done to the database by a cursor are immediately visible by the other cursors. Cursors created from different connections can or can not be isolated, depending on the connections’ isolation level. See also rollback() and commit() methods.

Cursors are not thread safe: a multithread application can create many cursors from the same connection and should use each cursor from a single thread. See Thread and process safety for details.

description

This read-only attribute is a sequence of 7-item sequences.

Each of these sequences is a named tuple (a regular tuple if collections.namedtuple() is not available) containing information describing one result column:

  1. name: the name of the column returned.
  2. type_code: the PostgreSQL OID of the column. You can use the pg_type system table to get more informations about the type. This is the value used by Psycopg to decide what Python type use to represent the value. See also Type casting of SQL types into Python objects.
  3. display_size: the actual length of the column in bytes. Obtaining this value is computationally intensive, so it is always None unless the PSYCOPG_DISPLAY_SIZE parameter is set at compile time. See also PQgetlength.
  4. internal_size: the size in bytes of the column associated to this column on the server. Set to a negative value for variable-size types See also PQfsize.
  5. precision: total number of significant digits in columns of type NUMERIC. None for other types.
  6. scale: count of decimal digits in the fractional part in columns of type NUMERIC. None for other types.
  7. null_ok: always None as not easy to retrieve from the libpq.

This attribute will be None for operations that do not return rows or if the cursor has not had an operation invoked via the execute*() methods yet.

Changed in version 2.4: if possible, columns descriptions are named tuple instead of regular tuples.

close()

Close the cursor now (rather than whenever del is executed). The cursor will be unusable from this point forward; an InterfaceError will be raised if any operation is attempted with the cursor.

closed

Read-only boolean attribute: specifies if the cursor is closed (True) or not (False).

DB API extension

The closed attribute is a Psycopg extension to the DB API 2.0.

New in version 2.0.7.

connection

Read-only attribute returning a reference to the connection object on which the cursor was created.

name

Read-only attribute containing the name of the cursor if it was creates as named cursor by connection.cursor(), or None if it is a client side cursor. See Server side cursors.

DB API extension

The name attribute is a Psycopg extension to the DB API 2.0.

Commands execution methods

execute(operation[, parameters])

Prepare and execute a database operation (query or command).

Parameters may be provided as sequence or mapping and will be bound to variables in the operation. Variables are specified either with positional (%s) or named (%(name)s) placeholders. See Passing parameters to SQL queries.

The method returns None. If a query was executed, the returned values can be retrieved using fetch*() methods.

executemany(operation, seq_of_parameters)

Prepare a database operation (query or command) and then execute it against all parameter tuples or mappings found in the sequence seq_of_parameters.

The function is mostly useful for commands that update the database: any result set returned by the query is discarded.

Parameters are bounded to the query using the same rules described in the execute() method.

callproc(procname[, parameters])

Call a stored database procedure with the given name. The sequence of parameters must contain one ll J4WMȇJ5uω@;t5SmlcR{Zmo]]COq̵ry,7+TRO'߇L{xZvzl,VN0a0W\1׸ir=) +S4=ܫ3Y ϗ4 sZ$h0Ej??@ߐw}6R}'ߍ͓ш.ǠU K7Vh+ҼQ4ЬFXoX/:nyCe"sMбiHAejN ¤`k 10t02xռ?.'46XXoRH.fn)Pn"?/xF=yQh55=Uf謯d @.HS$%Eu 3|0ظ*zT9YPQHP(8y-J+myASV'n>joq ˂dW- Pj$k3y et^%w2"4eJZ'eD@l@njS¸7}vdֱR'o _QV$HдC<6v&g!ΣRQVD.XʫfVgZ@؞Ӓ`n*0xCrYPsYi*DxhG&fA3Uh()"pVFؕT \A)\=3 %q|쵲,XrzMY0L{R7uBlhAOʹ.byu[Ikyof'tk Y̘JPkƄnx)M:ET譧](/*:sƮmR% #yhƆM!xA^ҝu(4Sց'kZ.׷0cnnÌZt. dT/]f?w1vRUK)Pfcb8.=?$#1pp0a [q+-ؿWfħʲY~ic\&>8 3^_~ȬϨ5/>CG%$+c_?~5 __Ua7 XnՕ|~}??ƒ{W~B߹d'^ɛ ~pΌc=q8vg&ߒkw/^dPc?c