aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/src/sgml/plpython.sgml2
-rw-r--r--src/pl/plpython/expected/plpython_types.out28
-rw-r--r--src/pl/plpython/expected/plpython_types_3.out28
-rw-r--r--src/pl/plpython/plpy_typeio.c10
-rw-r--r--src/pl/plpython/sql/plpython_types.sql10
5 files changed, 77 insertions, 1 deletions
diff --git a/doc/src/sgml/plpython.sgml b/doc/src/sgml/plpython.sgml
index c15188c3e00..dd50c4475da 100644
--- a/doc/src/sgml/plpython.sgml
+++ b/doc/src/sgml/plpython.sgml
@@ -302,7 +302,7 @@ $$ LANGUAGE plpythonu;
<para>
PostgreSQL <type>smallint</type> and <type>int</type> are
converted to Python <type>int</type>.
- PostgreSQL <type>bigint</type> is converted
+ PostgreSQL <type>bigint</type> and <type>oid</type> are converted
to <type>long</type> in Python 2 and to <type>int</type> in
Python 3.
</para>
diff --git a/src/pl/plpython/expected/plpython_types.out b/src/pl/plpython/expected/plpython_types.out
index 888161323d1..46413455c8b 100644
--- a/src/pl/plpython/expected/plpython_types.out
+++ b/src/pl/plpython/expected/plpython_types.out
@@ -321,6 +321,34 @@ CONTEXT: PL/Python function "test_type_conversion_float8"
(1 row)
+CREATE FUNCTION test_type_conversion_oid(x oid) RETURNS oid AS $$
+plpy.info(x, type(x))
+return x
+$$ LANGUAGE plpythonu;
+SELECT * FROM test_type_conversion_oid(100);
+INFO: (100L, <type 'long'>)
+CONTEXT: PL/Python function "test_type_conversion_oid"
+ test_type_conversion_oid
+--------------------------
+ 100
+(1 row)
+
+SELECT * FROM test_type_conversion_oid(2147483649);
+INFO: (2147483649L, <type 'long'>)
+CONTEXT: PL/Python function "test_type_conversion_oid"
+ test_type_conversion_oid
+--------------------------
+ 2147483649
+(1 row)
+
+SELECT * FROM test_type_conversion_oid(null);
+INFO: (None, <type 'NoneType'>)
+CONTEXT: PL/Python function "test_type_conversion_oid"
+ test_type_conversion_oid
+--------------------------
+
+(1 row)
+
CREATE FUNCTION test_type_conversion_text(x text) RETURNS text AS $$
plpy.info(x, type(x))
return x
diff --git a/src/pl/plpython/expected/plpython_types_3.out b/src/pl/plpython/expected/plpython_types_3.out
index d1ae86377bd..511ef5a4c9a 100644
--- a/src/pl/plpython/expected/plpython_types_3.out
+++ b/src/pl/plpython/expected/plpython_types_3.out
@@ -321,6 +321,34 @@ CONTEXT: PL/Python function "test_type_conversion_float8"
(1 row)
+CREATE FUNCTION test_type_conversion_oid(x oid) RETURNS oid AS $$
+plpy.info(x, type(x))
+return x
+$$ LANGUAGE plpython3u;
+SELECT * FROM test_type_conversion_oid(100);
+INFO: (100, <class 'int'>)
+CONTEXT: PL/Python function "test_type_conversion_oid"
+ test_type_conversion_oid
+--------------------------
+ 100
+(1 row)
+
+SELECT * FROM test_type_conversion_oid(2147483649);
+INFO: (2147483649, <class 'int'>)
+CONTEXT: PL/Python function "test_type_conversion_oid"
+ test_type_conversion_oid
+--------------------------
+ 2147483649
+(1 row)
+
+SELECT * FROM test_type_conversion_oid(null);
+INFO: (None, <class 'NoneType'>)
+CONTEXT: PL/Python function "test_type_conversion_oid"
+ test_type_conversion_oid
+--------------------------
+
+(1 row)
+
CREATE FUNCTION test_type_conversion_text(x text) RETURNS text AS $$
plpy.info(x, type(x))
return x
diff --git a/src/pl/plpython/plpy_typeio.c b/src/pl/plpython/plpy_typeio.c
index 2402c151a4f..0ad542f21e9 100644
--- a/src/pl/plpython/plpy_typeio.c
+++ b/src/pl/plpython/plpy_typeio.c
@@ -39,6 +39,7 @@ static PyObject *PLyFloat_FromNumeric(PLyDatumToOb *arg, Datum d);
static PyObject *PLyInt_FromInt16(PLyDatumToOb *arg, Datum d);
static PyObject *PLyInt_FromInt32(PLyDatumToOb *arg, Datum d);
static PyObject *PLyLong_FromInt64(PLyDatumToOb *arg, Datum d);
+static PyObject *PLyLong_FromOid(PLyDatumToOb *arg, Datum d);
static PyObject *PLyBytes_FromBytea(PLyDatumToOb *arg, Datum d);
static PyObject *PLyString_FromDatum(PLyDatumToOb *arg, Datum d);
static PyObject *PLyList_FromArray(PLyDatumToOb *arg, Datum d);
@@ -460,6 +461,9 @@ PLy_input_datum_func2(PLyDatumToOb *arg, Oid typeOid, HeapTuple typeTup)
case INT8OID:
arg->func = PLyLong_FromInt64;
break;
+ case OIDOID:
+ arg->func = PLyLong_FromOid;
+ break;
case BYTEAOID:
arg->func = PLyBytes_FromBytea;
break;
@@ -547,6 +551,12 @@ PLyLong_FromInt64(PLyDatumToOb *arg, Datum d)
}
static PyObject *
+PLyLong_FromOid(PLyDatumToOb *arg, Datum d)
+{
+ return PyLong_FromUnsignedLong(DatumGetObjectId(d));
+}
+
+static PyObject *
PLyBytes_FromBytea(PLyDatumToOb *arg, Datum d)
{
text *txt = DatumGetByteaP(d);
diff --git a/src/pl/plpython/sql/plpython_types.sql b/src/pl/plpython/sql/plpython_types.sql
index 82cd9d42680..6a50b4236db 100644
--- a/src/pl/plpython/sql/plpython_types.sql
+++ b/src/pl/plpython/sql/plpython_types.sql
@@ -119,6 +119,16 @@ SELECT * FROM test_type_conversion_float8(5000000000.5);
SELECT * FROM test_type_conversion_float8(null);
+CREATE FUNCTION test_type_conversion_oid(x oid) RETURNS oid AS $$
+plpy.info(x, type(x))
+return x
+$$ LANGUAGE plpythonu;
+
+SELECT * FROM test_type_conversion_oid(100);
+SELECT * FROM test_type_conversion_oid(2147483649);
+SELECT * FROM test_type_conversion_oid(null);
+
+
CREATE FUNCTION test_type_conversion_text(x text) RETURNS text AS $$
plpy.info(x, type(x))
return x