Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit425417d

Browse files
committed
Editorial improvements for recent plpython doc updates.
1 parent90f53d8 commit425417d

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

‎doc/src/sgml/plpython.sgml

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.34 2006/10/16 17:28:03 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.35 2006/10/21 18:33:05 tgl Exp $ -->
22

33
<chapter id="plpython">
44
<title>PL/Python - Python Procedural Language</title>
@@ -61,11 +61,11 @@ $$ LANGUAGE plpythonu;
6161

6262
<para>
6363
The body of a function is simply a Python script. When the function
64-
is called,all unnamedarguments are passed as elementsto the array
65-
<varname>args[]</varname> andnamed argumentsas ordinary variables to the
66-
Python script. The result is returned from the Python code in the usual way,
67-
with <literal>return</literal> or <literal>yield</literal> (in case of
68-
a resultset statement).
64+
is called,itsarguments are passed as elementsof the array
65+
<varname>args[]</varname>;named argumentsare also passed as ordinary
66+
variables to thePython script. The result is returned from the Python code
67+
in the usual way,with <literal>return</literal> or
68+
<literal>yield</literal> (in case ofa resultset statement).
6969
</para>
7070

7171
<para>
@@ -101,9 +101,9 @@ def __plpython_procedure_pymax_23456():
101101
the global <varname>args</varname> list. In the
102102
<function>pymax</function> example, <varname>args[0]</varname> contains
103103
whatever was passed in as the first argument and
104-
<varname>args[1]</varname> contains the second argument's value. Alternatively,
105-
one can use named parameters as shown in the example above. This greatly simplifies
106-
the reading and writingof<application>PL/Python</application> code.
104+
<varname>args[1]</varname> contains the second argument's
105+
value. Alternatively,one can use named parameters as shown in the example
106+
above. Useofnamed parameters is usually more readable.
107107
</para>
108108

109109
<para>
@@ -161,31 +161,27 @@ $$ LANGUAGE plpythonu;
161161

162162
<para>
163163
There are multiple ways to return row or composite types from a Python
164-
scripts. In following examplesweassumeto have:
164+
function. The following examples assumewe have:
165165

166166
<programlisting>
167-
CREATE TABLE named_value (
168-
name text,
169-
value integer
170-
);
171-
</programlisting>
172-
or
173-
<programlisting>
174167
CREATE TYPE named_value AS (
175168
name text,
176169
value integer
177170
);
178171
</programlisting>
179172

173+
A composite result can be returned as a:
174+
180175
<variablelist>
181176
<varlistentry>
182-
<term>Sequencetypes (tuple or list), but not<literal>set</literal> (because
177+
<term>Sequencetype (atuple or list, but notasetbecause
183178
it is not indexable)</term>
184179
<listitem>
185180
<para>
186-
Returned sequence objects must have the same number of items as
187-
composite types have fields. Item with index 0 is assigned to the first field
188-
of the composite type, 1 to second and so on. For example:
181+
Returned sequence objects must have the same number of items as the
182+
composite result type has fields. The item with index 0 is assigned to
183+
the first field of the composite type, 1 to the second and so on. For
184+
example:
189185

190186
<programlisting>
191187
CREATE FUNCTION make_pair (name text, value integer)
@@ -196,7 +192,7 @@ AS $$
196192
$$ LANGUAGE plpythonu;
197193
</programlisting>
198194

199-
To return SQL nullin any column, insert <symbol>None</symbol> at
195+
To returnaSQL nullfor any column, insert <symbol>None</symbol> at
200196
the corresponding position.
201197
</para>
202198
</listitem>
@@ -206,8 +202,8 @@ $$ LANGUAGE plpythonu;
206202
<term>Mapping (dictionary)</term>
207203
<listitem>
208204
<para>
209-
Valuefora composite type's column is retrieved from the mapping with
210-
the column name as key. Example:
205+
The valueforeach result type column is retrieved from the mapping
206+
withthe column name as key. Example:
211207

212208
<programlisting>
213209
CREATE FUNCTION make_pair (name text, value integer)
@@ -217,8 +213,9 @@ AS $$
217213
$$ LANGUAGE plpythonu;
218214
</programlisting>
219215

220-
Additional dictionary key/value pairs are ignored. Missing keys are
221-
treated as errors, i.e. to return an SQL null value for any column, insert
216+
Any extra dictionary key/value pairs are ignored. Missing keys are
217+
treated as errors.
218+
To return a SQL null value for any column, insert
222219
<symbol>None</symbol> with the corresponding column name as the key.
223220
</para>
224221
</listitem>
@@ -228,6 +225,7 @@ $$ LANGUAGE plpythonu;
228225
<term>Object (any object providing method <literal>__getattr__</literal>)</term>
229226
<listitem>
230227
<para>
228+
This works the same as a mapping.
231229
Example:
232230

233231
<programlisting>
@@ -261,9 +259,9 @@ $$ LANGUAGE plpythonu;
261259

262260
<para>
263261
A <application>PL/Python</application> function can also return sets of
264-
scalar or composite types. There areserveral ways to achieve this because
265-
the returned object is internally turned into an iterator.For following
266-
examples, let'sassumeto have composite type:
262+
scalar or composite types. There areseveral ways to achieve this because
263+
the returned object is internally turned into an iterator.The following
264+
examplesassumewe have composite type:
267265

268266
<programlisting>
269267
CREATE TYPE greeting AS (
@@ -272,10 +270,11 @@ CREATE TYPE greeting AS (
272270
);
273271
</programlisting>
274272

275-
Currently known iterable types are:
273+
A set result can be returned from a:
274+
276275
<variablelist>
277276
<varlistentry>
278-
<term>Sequencetypes (tuple, list, set)</term>
277+
<term>Sequencetype (tuple, list, set)</term>
279278
<listitem>
280279
<para>
281280
<programlisting>
@@ -341,19 +340,17 @@ $$ LANGUAGE plpythonu;
341340
<ulink url="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1483133&amp;group_id=5470&amp;atid=105470">bug #1483133</ulink>,
342341
some debug versions of Python 2.4
343342
(configured and compiled with option <literal>--with-pydebug</literal>)
344-
are known to crash the <productname>PostgreSQL</productname> server.
343+
are known to crash the <productname>PostgreSQL</productname> server
344+
when using an iterator to return a set result.
345345
Unpatched versions of Fedora 4 contain this bug.
346-
It does not happen in productionversion of Python or on patched
346+
It does not happen in productionversions of Python or on patched
347347
versions of Fedora 4.
348348
</para>
349349
</warning>
350350
</para>
351351
</listitem>
352352
</varlistentry>
353353
</variablelist>
354-
355-
Whenever new iterable types are added to Python language,
356-
<application>PL/Python</application> is ready to use it.
357354
</para>
358355

359356
<para>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp