<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>
(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
(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
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);
case INT8OID:
arg->func = PLyLong_FromInt64;
break;
+ case OIDOID:
+ arg->func = PLyLong_FromOid;
+ break;
case BYTEAOID:
arg->func = PLyBytes_FromBytea;
break;
return PyLong_FromLong(DatumGetInt64(d));
}
+static PyObject *
+PLyLong_FromOid(PLyDatumToOb *arg, Datum d)
+{
+ return PyLong_FromUnsignedLong(DatumGetObjectId(d));
+}
+
static PyObject *
PLyBytes_FromBytea(PLyDatumToOb *arg, Datum d)
{
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