Database Reference
In-Depth Information
Python
2
Python
3
PostgreSQL
Comments
real , double , numeric float float This may lose precision for numeric
values.
bytes No encoding conversion is done, nor
should any encoding be assumed.
bytea
str
text , char() ,
varchar() , and other
text types
On Python 2, the string will be in serv-
er encoding.
str
str
On Python 3, it is an unicode string.
All other types
PostgreSQL's type output function is
used to convert to this string.
str
str
Inside the function, all computation is done using Python types and the return
value is converted back to PostgreSQL using the following rules (this is a direct
quote from official PL/Python documentation at http://www.postgresql.org/docs/cur-
rent/static/plpython-data.html ) :
• When the PostgreSQL return type is Boolean, the return value will be
evaluated for truth according to the Python rules. That is, 0 and empty
string are false , but notably f is true .
• When the PostgreSQL return type is bytea , the return value will be con-
verted to a string (Python 2) or bytes (Python 3) using the respective
Python built-ins, with the result being converted bytea .
• For all other PostgreSQL return types, the returned Python value is con-
verted to a string using Python's built-in str , and the result is passed to
the input function of the PostgreSQL data type.
Search WWH ::




Custom Search