PageRenderTime 76ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/doc/html/cursor.html

https://github.com/hhru/lucid-python-psycopg2
HTML | 637 lines | 600 code | 37 blank | 0 comment | 0 complexity | 2a937c81f5b34b3527a2bf9077f37e4a MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>The cursor class &mdash; Psycopg v2.4.2 documentation</title>
  7. <link rel="stylesheet" href="_static/psycopg.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '',
  12. VERSION: '2.4.2',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="_static/jquery.js"></script>
  19. <script type="text/javascript" src="_static/underscore.js"></script>
  20. <script type="text/javascript" src="_static/doctools.js"></script>
  21. <link rel="top" title="Psycopg v2.4.2 documentation" href="index.html" />
  22. <link rel="next" title="More advanced topics" href="advanced.html" />
  23. <link rel="prev" title="The connection class" href="connection.html" />
  24. </head>
  25. <body>
  26. <div class="related">
  27. <h3>Navigation</h3>
  28. <ul>
  29. <li class="right" style="margin-right: 10px">
  30. <a href="genindex.html" title="General Index"
  31. accesskey="I">index</a></li>
  32. <li class="right" >
  33. <a href="py-modindex.html" title="Python Module Index"
  34. >modules</a> |</li>
  35. <li class="right" >
  36. <a href="advanced.html" title="More advanced topics"
  37. accesskey="N">next</a> |</li>
  38. <li class="right" >
  39. <a href="connection.html" title="The connection class"
  40. accesskey="P">previous</a> |</li>
  41. <li><a href="index.html">Psycopg v2.4.2 documentation</a> &raquo;</li>
  42. </ul>
  43. </div>
  44. <div class="document">
  45. <div class="documentwrapper">
  46. <div class="bodywrapper">
  47. <div class="body">
  48. <div class="section" id="the-cursor-class">
  49. <h1>The <tt class="docutils literal"><span class="pre">cursor</span></tt> class<a class="headerlink" href="#the-cursor-class" title="Permalink to this headline"></a></h1>
  50. <dl class="class">
  51. <dt id="cursor">
  52. <em class="property">class </em><tt class="descname">cursor</tt><a class="headerlink" href="#cursor" title="Permalink to this definition"></a></dt>
  53. <dd><p>Allows Python code to execute PostgreSQL command in a database session.
  54. Cursors are created by the <a class="reference internal" href="connection.html#connection.cursor" title="connection.cursor"><tt class="xref py py-obj docutils literal"><span class="pre">connection.cursor()</span></tt></a> method: they are
  55. bound to the connection for the entire lifetime and all the commands are
  56. executed in the context of the database session wrapped by the connection.</p>
  57. <p>Cursors created from the same connection are not isolated, i.e., any
  58. changes done to the database by a cursor are immediately visible by the
  59. other cursors. Cursors created from different connections can or can not
  60. be isolated, depending on the connections&#8217; <a class="reference internal" href="usage.html#transactions-control"><em>isolation level</em></a>. See also <a class="reference internal" href="connection.html#connection.rollback" title="connection.rollback"><tt class="xref py py-obj docutils literal"><span class="pre">rollback()</span></tt></a> and
  61. <a class="reference internal" href="connection.html#connection.commit" title="connection.commit"><tt class="xref py py-obj docutils literal"><span class="pre">commit()</span></tt></a> methods.</p>
  62. <p>Cursors are <em>not</em> thread safe: a multithread application can create
  63. many cursors from the same connection and should use each cursor from
  64. a single thread. See <a class="reference internal" href="usage.html#thread-safety"><em>Thread and process safety</em></a> for details.</p>
  65. <dl class="attribute">
  66. <dt id="cursor.description">
  67. <tt class="descname">description</tt><a class="headerlink" href="#cursor.description" title="Permalink to this definition"></a></dt>
  68. <dd><p>This read-only attribute is a sequence of 7-item sequences.</p>
  69. <p>Each of these sequences is a named tuple (a regular tuple if
  70. <a class="reference external" href="http://docs.python.org/3.2/library/collections.html#collections.namedtuple" title="(in Python v3.2)"><tt class="xref py py-func docutils literal"><span class="pre">collections.namedtuple()</span></tt></a> is not available) containing information
  71. describing one result column:</p>
  72. <ol class="arabic simple" start="0">
  73. <li><tt class="xref py py-obj docutils literal"><span class="pre">name</span></tt>: the name of the column returned.</li>
  74. <li><tt class="xref py py-obj docutils literal"><span class="pre">type_code</span></tt>: the PostgreSQL OID of the column. You can use the
  75. <a class="reference external" href="http://www.postgresql.org/docs/9.0/static/catalog-pg-type.html"><tt class="sql docutils literal"><span class="pre">pg_type</span></tt></a> system table to get more informations about the type.
  76. This is the value used by Psycopg to decide what Python type use
  77. to represent the value. See also
  78. <a class="reference internal" href="advanced.html#type-casting-from-sql-to-python"><em>Type casting of SQL types into Python objects</em></a>.</li>
  79. <li><tt class="xref py py-obj docutils literal"><span class="pre">display_size</span></tt>: the actual length of the column in bytes.
  80. Obtaining this value is computationally intensive, so it is
  81. always <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt> unless the <span class="target" id="index-0"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PSYCOPG_DISPLAY_SIZE</span></tt> parameter
  82. is set at compile time. See also <a class="reference external" href="http://www.postgresql.org/docs/9.0/static/libpq-exec.html#LIBPQ-PQGETLENGTH">PQgetlength</a>.</li>
  83. <li><tt class="xref py py-obj docutils literal"><span class="pre">internal_size</span></tt>: the size in bytes of the column associated to
  84. this column on the server. Set to a negative value for
  85. variable-size types See also <a class="reference external" href="http://www.postgresql.org/docs/9.0/static/libpq-exec.html#LIBPQ-PQFSIZE">PQfsize</a>.</li>
  86. <li><tt class="xref py py-obj docutils literal"><span class="pre">precision</span></tt>: total number of significant digits in columns of
  87. type <a class="reference external" href="http://www.postgresql.org/docs/9.0/static/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL"><tt class="sql docutils literal"><span class="pre">NUMERIC</span></tt></a>. <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt> for other types.</li>
  88. <li><tt class="xref py py-obj docutils literal"><span class="pre">scale</span></tt>: count of decimal digits in the fractional part in
  89. columns of type <tt class="sql docutils literal"><span class="pre">NUMERIC</span></tt>. <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt> for other types.</li>
  90. <li><tt class="xref py py-obj docutils literal"><span class="pre">null_ok</span></tt>: always <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt> as not easy to retrieve from the libpq.</li>
  91. </ol>
  92. <p>This attribute will be <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt> for operations that do not return rows
  93. or if the cursor has not had an operation invoked via the
  94. <a class="reference internal" href="#execute"><tt class="xref py py-obj docutils literal"><span class="pre">execute*()</span></tt></a> methods yet.</p>
  95. <p class="versionchanged">
  96. <span class="versionmodified">Changed in version 2.4: </span>if possible, columns descriptions are named tuple instead of
  97. regular tuples.</p>
  98. </dd></dl>
  99. <dl class="method">
  100. <dt id="cursor.close">
  101. <tt class="descname">close</tt><big>(</big><big>)</big><a class="headerlink" href="#cursor.close" title="Permalink to this definition"></a></dt>
  102. <dd><p>Close the cursor now (rather than whenever <tt class="xref py py-obj docutils literal"><span class="pre">del</span></tt> is executed).
  103. The cursor will be unusable from this point forward; an
  104. <a class="reference internal" href="module.html#psycopg2.InterfaceError" title="psycopg2.InterfaceError"><tt class="xref py py-obj docutils literal"><span class="pre">InterfaceError</span></tt></a> will be raised if any operation is
  105. attempted with the cursor.</p>
  106. </dd></dl>
  107. <dl class="attribute">
  108. <dt id="cursor.closed">
  109. <tt class="descname">closed</tt><a class="headerlink" href="#cursor.closed" title="Permalink to this definition"></a></dt>
  110. <dd><p>Read-only boolean attribute: specifies if the cursor is closed
  111. (<tt class="xref py py-obj xref docutils literal"><span class="pre">True</span></tt>) or not (<tt class="xref py py-obj xref docutils literal"><span class="pre">False</span></tt>).</p>
  112. <div class="admonition-db-api-extension dbapi-extension admonition ">
  113. <p class="first admonition-title">DB API extension</p>
  114. <p class="last">The <a class="reference internal" href="#cursor.closed" title="cursor.closed"><tt class="xref py py-obj docutils literal"><span class="pre">closed</span></tt></a> attribute is a Psycopg extension to the
  115. DB API 2.0.</p>
  116. </div>
  117. <p class="versionadded">
  118. <span class="versionmodified">New in version 2.0.7.</span></p>
  119. </dd></dl>
  120. <dl class="attribute">
  121. <dt id="cursor.connection">
  122. <tt class="descname">connection</tt><a class="headerlink" href="#cursor.connection" title="Permalink to this definition"></a></dt>
  123. <dd><p>Read-only attribute returning a reference to the <a class="reference internal" href="connection.html#connection" title="connection"><tt class="xref py py-obj docutils literal"><span class="pre">connection</span></tt></a>
  124. object on which the cursor was created.</p>
  125. </dd></dl>
  126. <dl class="attribute">
  127. <dt id="cursor.name">
  128. <tt class="descname">name</tt><a class="headerlink" href="#cursor.name" title="Permalink to this definition"></a></dt>
  129. <dd><p>Read-only attribute containing the name of the cursor if it was
  130. creates as named cursor by <a class="reference internal" href="connection.html#connection.cursor" title="connection.cursor"><tt class="xref py py-obj docutils literal"><span class="pre">connection.cursor()</span></tt></a>, or <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt> if
  131. it is a client side cursor. See <a class="reference internal" href="usage.html#server-side-cursors"><em>Server side cursors</em></a>.</p>
  132. <div class="admonition-db-api-extension dbapi-extension admonition ">
  133. <p class="first admonition-title">DB API extension</p>
  134. <p class="last">The <a class="reference internal" href="#cursor.name" title="cursor.name"><tt class="xref py py-obj docutils literal"><span class="pre">name</span></tt></a> attribute is a Psycopg extension to the DB API 2.0.</p>
  135. </div>
  136. </dd></dl>
  137. <p class="rubric" id="execute">Commands execution methods</p>
  138. <dl class="method">
  139. <dt id="cursor.execute">
  140. <tt class="descname">execute</tt><big>(</big><em>operation</em><span class="optional">[</span>, <em>parameters</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#cursor.execute" title="Permalink to this definition"></a></dt>
  141. <dd><p>Prepare and execute a database operation (query or command).</p>
  142. <p>Parameters may be provided as sequence or mapping and will be bound to
  143. variables in the operation. Variables are specified either with
  144. positional (<tt class="docutils literal"><span class="pre">%s</span></tt>) or named (<tt class="samp docutils literal"><span class="pre">%(</span><em><span class="pre">name</span></em><span class="pre">)s</span></tt>) placeholders. See
  145. <a class="reference internal" href="usage.html#query-parameters"><em>Passing parameters to SQL queries</em></a>.</p>
  146. <p>The method returns <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt>. If a query was executed, the returned
  147. values can be retrieved using <a class="reference internal" href="#fetch"><tt class="xref py py-obj docutils literal"><span class="pre">fetch*()</span></tt></a> methods.</p>
  148. </dd></dl>
  149. <dl class="method">
  150. <dt id="cursor.executemany">
  151. <tt class="descname">executemany</tt><big>(</big><em>operation</em>, <em>seq_of_parameters</em><big>)</big><a class="headerlink" href="#cursor.executemany" title="Permalink to this definition"></a></dt>
  152. <dd><p>Prepare a database operation (query or command) and then execute it
  153. against all parameter tuples or mappings found in the sequence
  154. <tt class="xref py py-obj docutils literal"><span class="pre">seq_of_parameters</span></tt>.</p>
  155. <p>The function is mostly useful for commands that update the database:
  156. any result set returned by the query is discarded.</p>
  157. <p>Parameters are bounded to the query using the same rules described in
  158. the <a class="reference internal" href="#cursor.execute" title="cursor.execute"><tt class="xref py py-obj docutils literal"><span class="pre">execute()</span></tt></a> method.</p>
  159. </dd></dl>
  160. <dl class="method">
  161. <dt id="cursor.callproc">
  162. <tt class="descname">callproc</tt><big>(</big><em>procname</em><span class="optional">[</span>, <em>parameters</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#cursor.callproc" title="Permalink to this definition"></a></dt>
  163. <dd><p>Call a stored database procedure with the given name. The sequence of
  164. parameters must contain one entry for each argument that the procedure
  165. expects. The result of the call is returned as modified copy of the
  166. input sequence. Input parameters are left untouched, output and
  167. input/output parameters replaced with possibly new values.</p>
  168. <p>The procedure may also provide a result set as output. This must then
  169. be made available through the standard <a class="reference internal" href="#fetch"><tt class="xref py py-obj docutils literal"><span class="pre">fetch*()</span></tt></a> methods.</p>
  170. </dd></dl>
  171. <dl class="method">
  172. <dt id="cursor.mogrify">
  173. <tt class="descname">mogrify</tt><big>(</big><em>operation</em><span class="optional">[</span>, <em>parameters</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#cursor.mogrify" title="Permalink to this definition"></a></dt>
  174. <dd><p>Return a query string after arguments binding. The string returned is
  175. exactly the one that would be sent to the database running the
  176. <a class="reference internal" href="#cursor.execute" title="cursor.execute"><tt class="xref py py-obj docutils literal"><span class="pre">execute()</span></tt></a> method or similar.</p>
  177. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">mogrify</span><span class="p">(</span><span class="s">&quot;INSERT INTO test (num, data) VALUES (</span><span class="si">%s</span><span class="s">, </span><span class="si">%s</span><span class="s">)&quot;</span><span class="p">,</span> <span class="p">(</span><span class="mi">42</span><span class="p">,</span> <span class="s">&#39;bar&#39;</span><span class="p">))</span>
  178. <span class="go">&quot;INSERT INTO test (num, data) VALUES (42, E&#39;bar&#39;)&quot;</span>
  179. </pre></div>
  180. </div>
  181. <div class="admonition-db-api-extension dbapi-extension admonition ">
  182. <p class="first admonition-title">DB API extension</p>
  183. <p class="last">The <a class="reference internal" href="#cursor.mogrify" title="cursor.mogrify"><tt class="xref py py-obj docutils literal"><span class="pre">mogrify()</span></tt></a> method is a Psycopg extension to the DB API 2.0.</p>
  184. </div>
  185. </dd></dl>
  186. <dl class="method">
  187. <dt id="cursor.setinputsizes">
  188. <tt class="descname">setinputsizes</tt><big>(</big><em>sizes</em><big>)</big><a class="headerlink" href="#cursor.setinputsizes" title="Permalink to this definition"></a></dt>
  189. <dd><p>This method is exposed in compliance with the DB API 2.0. It currently
  190. does nothing but it is safe to call it.</p>
  191. </dd></dl>
  192. <p class="rubric" id="fetch">Results retrieval methods</p>
  193. <p>The following methods are used to read data from the database after an
  194. <a class="reference internal" href="#cursor.execute" title="cursor.execute"><tt class="xref py py-obj docutils literal"><span class="pre">execute()</span></tt></a> call.</p>
  195. <div class="admonition note" id="cursor-iterable">
  196. <p class="first admonition-title">Note</p>
  197. <p><a class="reference internal" href="#cursor" title="cursor"><tt class="xref py py-obj docutils literal"><span class="pre">cursor</span></tt></a> objects are iterable, so, instead of calling
  198. explicitly <a class="reference internal" href="#cursor.fetchone" title="cursor.fetchone"><tt class="xref py py-obj docutils literal"><span class="pre">fetchone()</span></tt></a> in a loop, the object itself can
  199. be used:</p>
  200. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;SELECT * FROM test;&quot;</span><span class="p">)</span>
  201. <span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">cur</span><span class="p">:</span>
  202. <span class="gp">... </span> <span class="k">print</span> <span class="n">record</span>
  203. <span class="gp">...</span>
  204. <span class="go">(1, 100, &quot;abc&#39;def&quot;)</span>
  205. <span class="go">(2, None, &#39;dada&#39;)</span>
  206. <span class="go">(3, 42, &#39;bar&#39;)</span>
  207. </pre></div>
  208. </div>
  209. <p class="last versionchanged">
  210. <span class="versionmodified">Changed in version 2.4: </span>iterating over a <a class="reference internal" href="usage.html#server-side-cursors"><em>named cursor</em></a>
  211. fetches <a class="reference internal" href="#cursor.itersize" title="cursor.itersize"><tt class="xref py py-obj docutils literal"><span class="pre">itersize</span></tt></a> records at time from the backend.
  212. Previously only one record was fetched per roundtrip, resulting
  213. in a large overhead.</p>
  214. </div>
  215. <dl class="method">
  216. <dt id="cursor.fetchone">
  217. <tt class="descname">fetchone</tt><big>(</big><big>)</big><a class="headerlink" href="#cursor.fetchone" title="Permalink to this definition"></a></dt>
  218. <dd><p>Fetch the next row of a query result set, returning a single tuple,
  219. or <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt> when no more data is available:</p>
  220. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;SELECT * FROM test WHERE id = </span><span class="si">%s</span><span class="s">&quot;</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,))</span>
  221. <span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">fetchone</span><span class="p">()</span>
  222. <span class="go">(3, 42, &#39;bar&#39;)</span>
  223. </pre></div>
  224. </div>
  225. <p>A <a class="reference internal" href="module.html#psycopg2.ProgrammingError" title="psycopg2.ProgrammingError"><tt class="xref py py-obj docutils literal"><span class="pre">ProgrammingError</span></tt></a> is raised if the previous call
  226. to <a class="reference internal" href="#execute"><tt class="xref py py-obj docutils literal"><span class="pre">execute*()</span></tt></a> did not produce any result set or no call was issued
  227. yet.</p>
  228. </dd></dl>
  229. <dl class="method">
  230. <dt id="cursor.fetchmany">
  231. <tt class="descname">fetchmany</tt><big>(</big><span class="optional">[</span><em>size=cursor.arraysize</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#cursor.fetchmany" title="Permalink to this definition"></a></dt>
  232. <dd><p>Fetch the next set of rows of a query result, returning a list of
  233. tuples. An empty list is returned when no more rows are available.</p>
  234. <p>The number of rows to fetch per call is specified by the parameter.
  235. If it is not given, the cursor&#8217;s <a class="reference internal" href="#cursor.arraysize" title="cursor.arraysize"><tt class="xref py py-obj docutils literal"><span class="pre">arraysize</span></tt></a> determines
  236. the number of rows to be fetched. The method should try to fetch as
  237. many rows as indicated by the size parameter. If this is not possible
  238. due to the specified number of rows not being available, fewer rows
  239. may be returned:</p>
  240. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;SELECT * FROM test;&quot;</span><span class="p">)</span>
  241. <span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">fetchmany</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
  242. <span class="go">[(1, 100, &quot;abc&#39;def&quot;), (2, None, &#39;dada&#39;)]</span>
  243. <span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">fetchmany</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
  244. <span class="go">[(3, 42, &#39;bar&#39;)]</span>
  245. <span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">fetchmany</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
  246. <span class="go">[]</span>
  247. </pre></div>
  248. </div>
  249. <p>A <a class="reference internal" href="module.html#psycopg2.ProgrammingError" title="psycopg2.ProgrammingError"><tt class="xref py py-obj docutils literal"><span class="pre">ProgrammingError</span></tt></a> is raised if the previous call to
  250. <a class="reference internal" href="#execute"><tt class="xref py py-obj docutils literal"><span class="pre">execute*()</span></tt></a> did not produce any result set or no call was issued yet.</p>
  251. <p>Note there are performance considerations involved with the size
  252. parameter. For optimal performance, it is usually best to use the
  253. <a class="reference internal" href="#cursor.arraysize" title="cursor.arraysize"><tt class="xref py py-obj docutils literal"><span class="pre">arraysize</span></tt></a> attribute. If the size parameter is used,
  254. then it is best for it to retain the same value from one
  255. <a class="reference internal" href="#cursor.fetchmany" title="cursor.fetchmany"><tt class="xref py py-obj docutils literal"><span class="pre">fetchmany()</span></tt></a> call to the next.</p>
  256. </dd></dl>
  257. <dl class="method">
  258. <dt id="cursor.fetchall">
  259. <tt class="descname">fetchall</tt><big>(</big><big>)</big><a class="headerlink" href="#cursor.fetchall" title="Permalink to this definition"></a></dt>
  260. <dd><p>Fetch all (remaining) rows of a query result, returning them as a list
  261. of tuples. An empty list is returned if there is no more record to
  262. fetch.</p>
  263. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;SELECT * FROM test;&quot;</span><span class="p">)</span>
  264. <span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">fetchall</span><span class="p">()</span>
  265. <span class="go">[(1, 100, &quot;abc&#39;def&quot;), (2, None, &#39;dada&#39;), (3, 42, &#39;bar&#39;)]</span>
  266. </pre></div>
  267. </div>
  268. <p>A <a class="reference internal" href="module.html#psycopg2.ProgrammingError" title="psycopg2.ProgrammingError"><tt class="xref py py-obj docutils literal"><span class="pre">ProgrammingError</span></tt></a> is raised if the previous call to
  269. <a class="reference internal" href="#execute"><tt class="xref py py-obj docutils literal"><span class="pre">execute*()</span></tt></a> did not produce any result set or no call was issued yet.</p>
  270. </dd></dl>
  271. <dl class="method">
  272. <dt id="cursor.scroll">
  273. <tt class="descname">scroll</tt><big>(</big><em>value</em><span class="optional">[</span>, <em>mode='relative'</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#cursor.scroll" title="Permalink to this definition"></a></dt>
  274. <dd><p>Scroll the cursor in the result set to a new position according
  275. to mode.</p>
  276. <p>If <tt class="xref py py-obj docutils literal"><span class="pre">mode</span></tt> is <tt class="docutils literal"><span class="pre">relative</span></tt> (default), value is taken as offset to
  277. the current position in the result set, if set to <tt class="docutils literal"><span class="pre">absolute</span></tt>,
  278. value states an absolute target position.</p>
  279. <p>If the scroll operation would leave the result set, a
  280. <a class="reference internal" href="module.html#psycopg2.ProgrammingError" title="psycopg2.ProgrammingError"><tt class="xref py py-obj docutils literal"><span class="pre">ProgrammingError</span></tt></a> is raised and the cursor position is
  281. not changed.</p>
  282. <p>The method can be used both for client-side cursors and
  283. <a class="reference internal" href="usage.html#server-side-cursors"><em>server-side cursors</em></a>.</p>
  284. <div class="admonition note">
  285. <p class="first admonition-title">Note</p>
  286. <p>According to the <a class="reference external" href="http://www.python.org/dev/peps/pep-0249/">DB API 2.0</a>, the exception raised for a cursor out
  287. of bound should have been <tt class="xref py py-obj docutils literal"><span class="pre">IndexError</span></tt>. The best option is
  288. probably to catch both exceptions in your code:</p>
  289. <div class="last highlight-python"><div class="highlight"><pre><span class="k">try</span><span class="p">:</span>
  290. <span class="n">cur</span><span class="o">.</span><span class="n">scroll</span><span class="p">(</span><span class="mi">1000</span> <span class="o">*</span> <span class="mi">1000</span><span class="p">)</span>
  291. <span class="k">except</span> <span class="p">(</span><span class="n">ProgrammingError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">),</span> <span class="n">exc</span><span class="p">:</span>
  292. <span class="n">deal_with_it</span><span class="p">(</span><span class="n">exc</span><span class="p">)</span>
  293. </pre></div>
  294. </div>
  295. </div>
  296. </dd></dl>
  297. <dl class="attribute">
  298. <dt id="cursor.arraysize">
  299. <tt class="descname">arraysize</tt><a class="headerlink" href="#cursor.arraysize" title="Permalink to this definition"></a></dt>
  300. <dd><p>This read/write attribute specifies the number of rows to fetch at a
  301. time with <a class="reference internal" href="#cursor.fetchmany" title="cursor.fetchmany"><tt class="xref py py-obj docutils literal"><span class="pre">fetchmany()</span></tt></a>. It defaults to 1 meaning to fetch
  302. a single row at a time.</p>
  303. </dd></dl>
  304. <dl class="attribute">
  305. <dt id="cursor.itersize">
  306. <tt class="descname">itersize</tt><a class="headerlink" href="#cursor.itersize" title="Permalink to this definition"></a></dt>
  307. <dd><p>Read/write attribute specifying the number of rows to fetch from the
  308. backend at each network roundtrip during <a class="reference internal" href="#cursor-iterable"><em>iteration</em></a> on a <a class="reference internal" href="usage.html#server-side-cursors"><em>named cursor</em></a>. The
  309. default is 2000.</p>
  310. <p class="versionadded">
  311. <span class="versionmodified">New in version 2.4.</span></p>
  312. <div class="admonition-db-api-extension dbapi-extension admonition ">
  313. <p class="first admonition-title">DB API extension</p>
  314. <p class="last">The <a class="reference internal" href="#cursor.itersize" title="cursor.itersize"><tt class="xref py py-obj docutils literal"><span class="pre">itersize</span></tt></a> attribute is a Psycopg extension to the DB API 2.0.</p>
  315. </div>
  316. </dd></dl>
  317. <dl class="attribute">
  318. <dt id="cursor.rowcount">
  319. <tt class="descname">rowcount</tt><a class="headerlink" href="#cursor.rowcount" title="Permalink to this definition"></a></dt>
  320. <dd><p>This read-only attribute specifies the number of rows that the last
  321. <a class="reference internal" href="#execute"><tt class="xref py py-obj docutils literal"><span class="pre">execute*()</span></tt></a> produced (for <abbr title="Data Query Language">DQL</abbr> statements
  322. like <tt class="sql docutils literal"><span class="pre">SELECT</span></tt>) or affected (for
  323. <abbr title="Data Manipulation Language">DML</abbr> statements like <tt class="sql docutils literal"><span class="pre">UPDATE</span></tt>
  324. or <tt class="sql docutils literal"><span class="pre">INSERT</span></tt>).</p>
  325. <p>The attribute is -1 in case no <tt class="xref py py-obj docutils literal"><span class="pre">execute*()</span></tt> has been performed on
  326. the cursor or the row count of the last operation if it can&#8217;t be
  327. determined by the interface.</p>
  328. <div class="admonition note">
  329. <p class="first admonition-title">Note</p>
  330. <p class="last">The <a class="reference external" href="http://www.python.org/dev/peps/pep-0249/">DB API 2.0</a> interface reserves to redefine the latter case to
  331. have the object return <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt> instead of -1 in future versions
  332. of the specification.</p>
  333. </div>
  334. </dd></dl>
  335. <dl class="attribute">
  336. <dt id="cursor.rownumber">
  337. <tt class="descname">rownumber</tt><a class="headerlink" href="#cursor.rownumber" title="Permalink to this definition"></a></dt>
  338. <dd><p>This read-only attribute provides the current 0-based index of the
  339. cursor in the result set or <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt> if the index cannot be
  340. determined.</p>
  341. <p>The index can be seen as index of the cursor in a sequence (the result
  342. set). The next fetch operation will fetch the row indexed by
  343. <a class="reference internal" href="#cursor.rownumber" title="cursor.rownumber"><tt class="xref py py-obj docutils literal"><span class="pre">rownumber</span></tt></a> in that sequence.</p>
  344. </dd></dl>
  345. <span class="target" id="index-1"></span><dl class="attribute">
  346. <dt id="cursor.lastrowid">
  347. <tt class="descname">lastrowid</tt><a class="headerlink" href="#cursor.lastrowid" title="Permalink to this definition"></a></dt>
  348. <dd><p>This read-only attribute provides the OID of the last row inserted
  349. by the cursor. If the table wasn&#8217;t created with OID support or the
  350. last operation is not a single record insert, the attribute is set to
  351. <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt>.</p>
  352. <div class="admonition note">
  353. <p class="first admonition-title">Note</p>
  354. <p class="last">PostgreSQL currently advices to not create OIDs on the tables and
  355. the default for <a class="reference external" href="http://www.postgresql.org/docs/9.0/static/sql-createtable.html"><tt class="sql docutils literal"><span class="pre">CREATE</span> <span class="pre">TABLE</span></tt></a> is to not support them. The
  356. <a class="reference external" href="http://www.postgresql.org/docs/9.0/static/sql-insert.html"><tt class="sql docutils literal"><span class="pre">INSERT</span> <span class="pre">...</span> <span class="pre">RETURNING</span></tt></a> syntax available from PostgreSQL 8.3 allows
  357. more flexibility.</p>
  358. </div>
  359. </dd></dl>
  360. <dl class="attribute">
  361. <dt id="cursor.query">
  362. <tt class="descname">query</tt><a class="headerlink" href="#cursor.query" title="Permalink to this definition"></a></dt>
  363. <dd><p>Read-only attribute containing the body of the last query sent to the
  364. backend (including bound arguments). <tt class="xref py py-obj xref docutils literal"><span class="pre">None</span></tt> if no query has been
  365. executed yet:</p>
  366. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;INSERT INTO test (num, data) VALUES (</span><span class="si">%s</span><span class="s">, </span><span class="si">%s</span><span class="s">)&quot;</span><span class="p">,</span> <span class="p">(</span><span class="mi">42</span><span class="p">,</span> <span class="s">&#39;bar&#39;</span><span class="p">))</span>
  367. <span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">query</span>
  368. <span class="go">&quot;INSERT INTO test (num, data) VALUES (42, E&#39;bar&#39;)&quot;</span>
  369. </pre></div>
  370. </div>
  371. <div class="admonition-db-api-extension dbapi-extension admonition ">
  372. <p class="first admonition-title">DB API extension</p>
  373. <p class="last">The <a class="reference internal" href="#cursor.query" title="cursor.query"><tt class="xref py py-obj docutils literal"><span class="pre">query</span></tt></a> attribute is a Psycopg extension to the DB API 2.0.</p>
  374. </div>
  375. </dd></dl>
  376. <dl class="attribute">
  377. <dt id="cursor.statusmessage">
  378. <tt class="descname">statusmessage</tt><a class="headerlink" href="#cursor.statusmessage" title="Permalink to this definition"></a></dt>
  379. <dd><p>Read-only attribute containing the message returned by the last
  380. command:</p>
  381. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;INSERT INTO test (num, data) VALUES (</span><span class="si">%s</span><span class="s">, </span><span class="si">%s</span><span class="s">)&quot;</span><span class="p">,</span> <span class="p">(</span><span class="mi">42</span><span class="p">,</span> <span class="s">&#39;bar&#39;</span><span class="p">))</span>
  382. <span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">statusmessage</span>
  383. <span class="go">&#39;INSERT 0 1&#39;</span>
  384. </pre></div>
  385. </div>
  386. <div class="admonition-db-api-extension dbapi-extension admonition ">
  387. <p class="first admonition-title">DB API extension</p>
  388. <p class="last">The <a class="reference internal" href="#cursor.statusmessage" title="cursor.statusmessage"><tt class="xref py py-obj docutils literal"><span class="pre">statusmessage</span></tt></a> attribute is a Psycopg extension to the
  389. DB API 2.0.</p>
  390. </div>
  391. </dd></dl>
  392. <dl class="method">
  393. <dt id="cursor.cast">
  394. <tt class="descname">cast</tt><big>(</big><em>oid</em>, <em>s</em><big>)</big><a class="headerlink" href="#cursor.cast" title="Permalink to this definition"></a></dt>
  395. <dd><p>Convert a value from the PostgreSQL string representation to a Python
  396. object.</p>
  397. <p>Use the most specific of the typecasters registered by
  398. <a class="reference internal" href="extensions.html#psycopg2.extensions.register_type" title="psycopg2.extensions.register_type"><tt class="xref py py-obj docutils literal"><span class="pre">register_type()</span></tt></a>.</p>
  399. <p class="versionadded">
  400. <span class="versionmodified">New in version 2.4.</span></p>
  401. <div class="admonition-db-api-extension dbapi-extension admonition ">
  402. <p class="first admonition-title">DB API extension</p>
  403. <p class="last">The <a class="reference internal" href="#cursor.cast" title="cursor.cast"><tt class="xref py py-obj docutils literal"><span class="pre">cast()</span></tt></a> method is a Psycopg extension to the DB API 2.0.</p>
  404. </div>
  405. </dd></dl>
  406. <dl class="attribute">
  407. <dt id="cursor.tzinfo_factory">
  408. <tt class="descname">tzinfo_factory</tt><a class="headerlink" href="#cursor.tzinfo_factory" title="Permalink to this definition"></a></dt>
  409. <dd><p>The time zone factory used to handle data types such as
  410. <tt class="sql docutils literal"><span class="pre">TIMESTAMP</span> <span class="pre">WITH</span> <span class="pre">TIME</span> <span class="pre">ZONE</span></tt>. It should be a <a class="reference external" href="http://docs.python.org/3.2/library/datetime.html#datetime.tzinfo" title="(in Python v3.2)"><tt class="xref py py-obj docutils literal"><span class="pre">tzinfo</span></tt></a>
  411. object. A few implementations are available in the <a class="reference internal" href="tz.html#module-psycopg2.tz" title="psycopg2.tz"><tt class="xref py py-obj docutils literal"><span class="pre">psycopg2.tz</span></tt></a>
  412. module.</p>
  413. </dd></dl>
  414. <dl class="method">
  415. <dt id="cursor.nextset">
  416. <tt class="descname">nextset</tt><big>(</big><big>)</big><a class="headerlink" href="#cursor.nextset" title="Permalink to this definition"></a></dt>
  417. <dd><p>This method is not supported (PostgreSQL does not have multiple data
  418. sets) and will raise a <a class="reference internal" href="module.html#psycopg2.NotSupportedError" title="psycopg2.NotSupportedError"><tt class="xref py py-obj docutils literal"><span class="pre">NotSupportedError</span></tt></a> exception.</p>
  419. </dd></dl>
  420. <dl class="method">
  421. <dt id="cursor.setoutputsize">
  422. <tt class="descname">setoutputsize</tt><big>(</big><em>size</em><span class="optional">[</span>, <em>column</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#cursor.setoutputsize" title="Permalink to this definition"></a></dt>
  423. <dd><p>This method is exposed in compliance with the DB API 2.0. It currently
  424. does nothing but it is safe to call it.</p>
  425. </dd></dl>
  426. <p class="rubric">COPY-related methods</p>
  427. <div class="admonition-db-api-extension dbapi-extension admonition ">
  428. <p class="first admonition-title">DB API extension</p>
  429. <p class="last">The <tt class="sql docutils literal"><span class="pre">COPY</span></tt> command is a PostgreSQL extension to the SQL standard.
  430. As such, its support is a Psycopg extension to the DB API 2.0.</p>
  431. </div>
  432. <dl class="method">
  433. <dt id="cursor.copy_from">
  434. <tt class="descname">copy_from</tt><big>(</big><em>file</em>, <em>table</em>, <em>sep='\t'</em>, <em>null='\N'</em>, <em>size=8192</em>, <em>columns=None</em><big>)</big><a class="headerlink" href="#cursor.copy_from" title="Permalink to this definition"></a></dt>
  435. <dd><p>Read data <em>from</em> the file-like object <em>file</em> appending them to
  436. the table named <em>table</em>. See <a class="reference internal" href="usage.html#copy"><em>Using COPY TO and COPY FROM</em></a> for an overview.</p>
  437. <table class="docutils field-list" frame="void" rules="none">
  438. <col class="field-name" />
  439. <col class="field-body" />
  440. <tbody valign="top">
  441. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  442. <li><strong>file</strong> &#8211; file-like object to read data from. It must have both
  443. <tt class="xref py py-obj docutils literal"><span class="pre">read()</span></tt> and <tt class="xref py py-obj docutils literal"><span class="pre">readline()</span></tt> methods.</li>
  444. <li><strong>table</strong> &#8211; name of the table to copy data into.</li>
  445. <li><strong>sep</strong> &#8211; columns separator expected in the file. Defaults to a tab.</li>
  446. <li><strong>null</strong> &#8211; textual representation of <tt class="sql docutils literal"><span class="pre">NULL</span></tt> in the file.</li>
  447. <li><strong>size</strong> &#8211; size of the buffer used to read from the file.</li>
  448. <li><strong>columns</strong> &#8211; iterable with name of the columns to import.
  449. The length and types should match the content of the file to read.
  450. If not specified, it is assumed that the entire table matches the
  451. file structure.</li>
  452. </ul>
  453. </td>
  454. </tr>
  455. </tbody>
  456. </table>
  457. <p>Example:</p>
  458. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="s">&quot;42</span><span class="se">\t</span><span class="s">foo</span><span class="se">\n</span><span class="s">74</span><span class="se">\t</span><span class="s">bar</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">)</span>
  459. <span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">copy_from</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="s">&#39;test&#39;</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;num&#39;</span><span class="p">,</span> <span class="s">&#39;data&#39;</span><span class="p">))</span>
  460. <span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">&quot;select * from test where id &gt; 5;&quot;</span><span class="p">)</span>
  461. <span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">fetchall</span><span class="p">()</span>
  462. <span class="go">[(6, 42, &#39;foo&#39;), (7, 74, &#39;bar&#39;)]</span>
  463. </pre></div>
  464. </div>
  465. <p class="versionchanged">
  466. <span class="versionmodified">Changed in version 2.0.6: </span>added the <em>columns</em> parameter.</p>
  467. <p class="versionchanged">
  468. <span class="versionmodified">Changed in version 2.4: </span>data read from files implementing the <a class="reference external" href="http://docs.python.org/3.2/library/io.html#io.TextIOBase" title="(in Python v3.2)"><tt class="xref py py-obj docutils literal"><span class="pre">io.TextIOBase</span></tt></a> interface
  469. are encoded in the connection <a class="reference internal" href="connection.html#connection.encoding" title="connection.encoding"><tt class="xref py py-obj docutils literal"><span class="pre">encoding</span></tt></a> when sent to
  470. the backend.</p>
  471. </dd></dl>
  472. <dl class="method">
  473. <dt id="cursor.copy_to">
  474. <tt class="descname">copy_to</tt><big>(</big><em>file</em>, <em>table</em>, <em>sep='\t'</em>, <em>null='\N'</em>, <em>columns=None</em><big>)</big><a class="headerlink" href="#cursor.copy_to" title="Permalink to this definition"></a></dt>
  475. <dd><p>Write the content of the table named <em>table</em> <em>to</em> the file-like
  476. object <em>file</em>. See <a class="reference internal" href="usage.html#copy"><em>Using COPY TO and COPY FROM</em></a> for an overview.</p>
  477. <table class="docutils field-list" frame="void" rules="none">
  478. <col class="field-name" />
  479. <col class="field-body" />
  480. <tbody valign="top">
  481. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  482. <li><strong>file</strong> &#8211; file-like object to write data into. It must have a
  483. <tt class="xref py py-obj docutils literal"><span class="pre">write()</span></tt> method.</li>
  484. <li><strong>table</strong> &#8211; name of the table to copy data from.</li>
  485. <li><strong>sep</strong> &#8211; columns separator expected in the file. Defaults to a tab.</li>
  486. <li><strong>null</strong> &#8211; textual representation of <tt class="sql docutils literal"><span class="pre">NULL</span></tt> in the file.</li>
  487. <li><strong>columns</strong> &#8211; iterable with name of the columns to export.
  488. If not specified, export all the columns.</li>
  489. </ul>
  490. </td>
  491. </tr>
  492. </tbody>
  493. </table>
  494. <p>Example:</p>
  495. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">copy_to</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span> <span class="s">&#39;test&#39;</span><span class="p">,</span> <span class="n">sep</span><span class="o">=</span><span class="s">&quot;|&quot;</span><span class="p">)</span>
  496. <span class="go">1|100|abc&#39;def</span>
  497. <span class="go">2|\N|dada</span>
  498. <span class="gp">...</span>
  499. </pre></div>
  500. </div>
  501. <p class="versionchanged">
  502. <span class="versionmodified">Changed in version 2.0.6: </span>added the <em>columns</em> parameter.</p>
  503. <p class="versionchanged">
  504. <span class="versionmodified">Changed in version 2.4: </span>data sent to files implementing the <a class="reference external" href="http://docs.python.org/3.2/library/io.html#io.TextIOBase" title="(in Python v3.2)"><tt class="xref py py-obj docutils literal"><span class="pre">io.TextIOBase</span></tt></a> interface
  505. are decoded in the connection <a class="reference internal" href="connection.html#connection.encoding" title="connection.encoding"><tt class="xref py py-obj docutils literal"><span class="pre">encoding</span></tt></a> when read
  506. from the backend.</p>
  507. </dd></dl>
  508. <dl class="method">
  509. <dt id="cursor.copy_expert">
  510. <tt class="descname">copy_expert</tt><big>(</big><em>sql</em>, <em>file</em>, <em>size=8192</em><big>)</big><a class="headerlink" href="#cursor.copy_expert" title="Permalink to this definition"></a></dt>
  511. <dd><p>Submit a user-composed <tt class="sql docutils literal"><span class="pre">COPY</span></tt> statement. The method is useful to
  512. handle all the parameters that PostgreSQL makes available (see
  513. <a class="reference external" href="http://www.postgresql.org/docs/9.0/static/sql-copy.html"><tt class="sql docutils literal"><span class="pre">COPY</span></tt></a> command documentation).</p>
  514. <table class="docutils field-list" frame="void" rules="none">
  515. <col class="field-name" />
  516. <col class="field-body" />
  517. <tbody valign="top">
  518. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  519. <li><strong>sql</strong> &#8211; the <tt class="sql docutils literal"><span class="pre">COPY</span></tt> statement to execute.</li>
  520. <li><strong>file</strong> &#8211; a file-like object; must be a readable file for
  521. <tt class="sql docutils literal"><span class="pre">COPY</span> <span class="pre">FROM</span></tt> or an writeable file for <tt class="sql docutils literal"><span class="pre">COPY</span> <span class="pre">TO</span></tt>.</li>
  522. <li><strong>size</strong> &#8211; size of the read buffer to be used in <tt class="sql docutils literal"><span class="pre">COPY</span> <span class="pre">FROM</span></tt>.</li>
  523. </ul>
  524. </td>
  525. </tr>
  526. </tbody>
  527. </table>
  528. <p>Example:</p>
  529. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">cur</span><span class="o">.</span><span class="n">copy_expert</span><span class="p">(</span><span class="s">&quot;COPY test TO STDOUT WITH CSV HEADER&quot;</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span>
  530. <span class="go">id,num,data</span>
  531. <span class="go">1,100,abc&#39;def</span>
  532. <span class="go">2,,dada</span>
  533. <span class="gp">...</span>
  534. </pre></div>
  535. </div>
  536. <p class="versionadded">
  537. <span class="versionmodified">New in version 2.0.6.</span></p>
  538. <p class="versionchanged">
  539. <span class="versionmodified">Changed in version 2.4: </span>files implementing the <a class="reference external" href="http://docs.python.org/3.2/library/io.html#io.TextIOBase" title="(in Python v3.2)"><tt class="xref py py-obj docutils literal"><span class="pre">io.TextIOBase</span></tt></a> interface are dealt with
  540. using Unicode data instead of bytes.</p>
  541. </dd></dl>
  542. </dd></dl>
  543. </div>
  544. </div>
  545. </div>
  546. </div>
  547. <div class="sphinxsidebar">
  548. <div class="sphinxsidebarwrapper">
  549. <h4>Previous topic</h4>
  550. <p class="topless"><a href="connection.html"
  551. title="previous chapter">The <tt class="docutils literal docutils literal"><span class="pre">connection</span></tt> class</a></p>
  552. <h4>Next topic</h4>
  553. <p class="topless"><a href="advanced.html"
  554. title="next chapter">More advanced topics</a></p>
  555. <h3>This Page</h3>
  556. <ul class="this-page-menu">
  557. <li><a href="_sources/cursor.txt"
  558. rel="nofollow">Show Source</a></li>
  559. </ul>
  560. <div id="searchbox" style="display: none">
  561. <h3>Quick search</h3>
  562. <form class="search" action="search.html" method="get">
  563. <input type="text" name="q" size="18" />
  564. <input type="submit" value="Go" />
  565. <input type="hidden" name="check_keywords" value="yes" />
  566. <input type="hidden" name="area" value="default" />
  567. </form>
  568. <p class="searchtip" style="font-size: 90%">
  569. Enter search terms or a module, class or function name.
  570. </p>
  571. </div>
  572. <script type="text/javascript">$('#searchbox').show(0);</script>
  573. </div>
  574. </div>
  575. <div class="clearer"></div>
  576. </div>
  577. <div class="related">
  578. <h3>Navigation</h3>
  579. <ul>
  580. <li class="right" style="margin-right: 10px">
  581. <a href="genindex.html" title="General Index"
  582. >index</a></li>
  583. <li class="right" >
  584. <a href="py-modindex.html" title="Python Module Index"
  585. >modules</a> |</li>
  586. <li class="right" >
  587. <a href="advanced.html" title="More advanced topics"
  588. >next</a> |</li>
  589. <li class="right" >
  590. <a href="connection.html" title="The connection class"
  591. >previous</a> |</li>
  592. <li><a href="index.html">Psycopg v2.4.2 documentation</a> &raquo;</li>
  593. </ul>
  594. </div>
  595. <div class="footer">
  596. &copy; Copyright 2001-2011, Federico Di Gregorio. Documentation by Daniele Varrazzo.
  597. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
  598. </div>
  599. </body>
  600. </html>