pgsql: Fix/improve bytea and boolean support in PL/Python Before, - Mailing list pgsql-committers

From petere@postgresql.org (Peter Eisentraut)
Subject pgsql: Fix/improve bytea and boolean support in PL/Python Before,
Date
Msg-id 20090909190009.D8295753FB7@cvs.postgresql.org
Whole thread Raw
List pgsql-committers
Log Message:
-----------
Fix/improve bytea and boolean support in PL/Python

Before, PL/Python converted data between SQL and Python by going
through a C string representation.  This broke for bytea in two ways:

- On input (function parameters), you would get a Python string that
  contains bytea's particular external representation with backslashes
  etc., instead of a sequence of bytes, which is what you would expect
  in a Python environment.  This problem is exacerbated by the new
  bytea output format.

- On output (function return value), null bytes in the Python string
  would cause truncation before the data gets stored into a bytea
  datum.

This is now fixed by converting directly between the PostgreSQL datum
and the Python representation.

The required generalized infrastructure also allows for other
improvements in passing:

- When returning a boolean value, the SQL datum is now true if and
  only if Python considers the value that was passed out of the
  PL/Python function to be true.  Previously, this determination was
  left to the boolean data type input function.  So, now returning
  'foo' results in true, because Python considers it true, rather than
  false because PostgreSQL considers it false.

- On input, we can convert the integer and float types directly to
  their Python equivalents without having to go through an
  intermediate string representation.

original patch by Caleb Welton, with updates by myself

Modified Files:
--------------
    pgsql/src/backend/utils/adt:
        domains.c (r1.8 -> r1.9)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/adt/domains.c?r1=1.8&r2=1.9)
    pgsql/src/include/utils:
        builtins.h (r1.338 -> r1.339)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/utils/builtins.h?r1=1.338&r2=1.339)
    pgsql/src/pl/plpython:
        plpython.c (r1.127 -> r1.128)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/pl/plpython/plpython.c?r1=1.127&r2=1.128)
    pgsql/src/pl/plpython/expected:
        plpython_types.out (r1.3 -> r1.4)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/pl/plpython/expected/plpython_types.out?r1=1.3&r2=1.4)
    pgsql/src/pl/plpython/sql:
        plpython_types.sql (r1.2 -> r1.3)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/pl/plpython/sql/plpython_types.sql?r1=1.2&r2=1.3)

pgsql-committers by date:

Previous
From: tgl@postgresql.org (Tom Lane)
Date:
Subject: pgsql: Fix bug with WITH RECURSIVE immediately inside WITH RECURSIVE.
Next
From: heikki@postgresql.org (Heikki Linnakangas)
Date:
Subject: pgsql: On Windows, when a file is deleted and another process still has