gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

87 行
7.4KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>45.1. Python 2 vs. Python 3</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="plpython.html" title="Chapter 45. PL/Python - Python Procedural Language" /><link rel="next" href="plpython-funcs.html" title="45.2. PL/Python Functions" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">45.1. Python 2 vs. Python 3</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="plpython.html" title="Chapter 45. PL/Python - Python Procedural Language">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="plpython.html" title="Chapter 45. PL/Python - Python Procedural Language">Up</a></td><th width="60%" align="center">Chapter 45. PL/Python - Python Procedural Language</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="plpython-funcs.html" title="45.2. PL/Python Functions">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="PLPYTHON-PYTHON23"><div class="titlepage"><div><div><h2 class="title" style="clear: both">45.1. Python 2 vs. Python 3</h2></div></div></div><p>
  3. PL/Python supports both the Python 2 and Python 3 language
  4. variants. (The PostgreSQL installation instructions might contain
  5. more precise information about the exact supported minor versions
  6. of Python.) Because the Python 2 and Python 3 language variants
  7. are incompatible in some important aspects, the following naming
  8. and transitioning scheme is used by PL/Python to avoid mixing them:
  9. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  10. The PostgreSQL language named <code class="literal">plpython2u</code>
  11. implements PL/Python based on the Python 2 language variant.
  12. </p></li><li class="listitem"><p>
  13. The PostgreSQL language named <code class="literal">plpython3u</code>
  14. implements PL/Python based on the Python 3 language variant.
  15. </p></li><li class="listitem"><p>
  16. The language named <code class="literal">plpythonu</code> implements
  17. PL/Python based on the default Python language variant, which is
  18. currently Python 2. (This default is independent of what any
  19. local Python installations might consider to be
  20. their <span class="quote">“<span class="quote">default</span>”</span>, for example,
  21. what <code class="filename">/usr/bin/python</code> might be.) The
  22. default will probably be changed to Python 3 in a distant future
  23. release of PostgreSQL, depending on the progress of the
  24. migration to Python 3 in the Python community.
  25. </p></li></ul></div><p>
  26. This scheme is analogous to the recommendations in <a class="ulink" href="https://www.python.org/dev/peps/pep-0394/" target="_top">PEP 394</a> regarding the
  27. naming and transitioning of the <code class="command">python</code> command.
  28. </p><p>
  29. It depends on the build configuration or the installed packages
  30. whether PL/Python for Python 2 or Python 3 or both are available.
  31. </p><div class="tip"><h3 class="title">Tip</h3><p>
  32. The built variant depends on which Python version was found during
  33. the installation or which version was explicitly set using
  34. the <code class="envar">PYTHON</code> environment variable;
  35. see <a class="xref" href="install-procedure.html" title="16.4. Installation Procedure">Section 16.4</a>. To make both variants of
  36. PL/Python available in one installation, the source tree has to be
  37. configured and built twice.
  38. </p></div><p>
  39. This results in the following usage and migration strategy:
  40. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  41. Existing users and users who are currently not interested in
  42. Python 3 use the language name <code class="literal">plpythonu</code> and
  43. don't have to change anything for the foreseeable future. It is
  44. recommended to gradually <span class="quote">“<span class="quote">future-proof</span>”</span> the code
  45. via migration to Python 2.6/2.7 to simplify the eventual
  46. migration to Python 3.
  47. </p><p>
  48. In practice, many PL/Python functions will migrate to Python 3
  49. with few or no changes.
  50. </p></li><li class="listitem"><p>
  51. Users who know that they have heavily Python 2 dependent code
  52. and don't plan to ever change it can make use of
  53. the <code class="literal">plpython2u</code> language name. This will
  54. continue to work into the very distant future, until Python 2
  55. support might be completely dropped by PostgreSQL.
  56. </p></li><li class="listitem"><p>
  57. Users who want to dive into Python 3 can use
  58. the <code class="literal">plpython3u</code> language name, which will keep
  59. working forever by today's standards. In the distant future,
  60. when Python 3 might become the default, they might like to
  61. remove the <span class="quote">“<span class="quote">3</span>”</span> for aesthetic reasons.
  62. </p></li><li class="listitem"><p>
  63. Daredevils, who want to build a Python-3-only operating system
  64. environment, can change the contents of
  65. <a class="link" href="catalog-pg-pltemplate.html" title="51.37. pg_pltemplate"><code class="structname">pg_pltemplate</code></a>
  66. to make <code class="literal">plpythonu</code> be equivalent
  67. to <code class="literal">plpython3u</code>, keeping in mind that this
  68. would make their installation incompatible with most of the rest
  69. of the world.
  70. </p></li></ul></div><p>
  71. </p><p>
  72. See also the
  73. document <a class="ulink" href="https://docs.python.org/3/whatsnew/3.0.html" target="_top">What's
  74. New In Python 3.0</a> for more information about porting to
  75. Python 3.
  76. </p><p>
  77. It is not allowed to use PL/Python based on Python 2 and PL/Python
  78. based on Python 3 in the same session, because the symbols in the
  79. dynamic modules would clash, which could result in crashes of the
  80. PostgreSQL server process. There is a check that prevents mixing
  81. Python major versions in a session, which will abort the session if
  82. a mismatch is detected. It is possible, however, to use both
  83. PL/Python variants in the same database, from separate sessions.
  84. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="plpython.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="plpython.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="plpython-funcs.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 45. PL/Python - Python Procedural Language </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 45.2. PL/Python Functions</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1