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

Commitdb0af74

Browse files
committed
PL/Python: Convert oid to long/int
oid is a numeric type, so transform it to the appropriate Pythonnumeric type like the other ones.
1 parent811ca13 commitdb0af74

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

‎doc/src/sgml/plpython.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ $$ LANGUAGE plpythonu;
302302
<para>
303303
PostgreSQL <type>smallint</type> and <type>int</type> are
304304
converted to Python <type>int</type>.
305-
PostgreSQL <type>bigint</type>is converted
305+
PostgreSQL <type>bigint</type>and <type>oid</type> are converted
306306
to <type>long</type> in Python 2 and to <type>int</type> in
307307
Python 3.
308308
</para>

‎src/pl/plpython/expected/plpython_types.out

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,34 @@ CONTEXT: PL/Python function "test_type_conversion_float8"
321321

322322
(1 row)
323323

324+
CREATE FUNCTION test_type_conversion_oid(x oid) RETURNS oid AS $$
325+
plpy.info(x, type(x))
326+
return x
327+
$$ LANGUAGE plpythonu;
328+
SELECT * FROM test_type_conversion_oid(100);
329+
INFO: (100L, <type 'long'>)
330+
CONTEXT: PL/Python function "test_type_conversion_oid"
331+
test_type_conversion_oid
332+
--------------------------
333+
100
334+
(1 row)
335+
336+
SELECT * FROM test_type_conversion_oid(2147483649);
337+
INFO: (2147483649L, <type 'long'>)
338+
CONTEXT: PL/Python function "test_type_conversion_oid"
339+
test_type_conversion_oid
340+
--------------------------
341+
2147483649
342+
(1 row)
343+
344+
SELECT * FROM test_type_conversion_oid(null);
345+
INFO: (None, <type 'NoneType'>)
346+
CONTEXT: PL/Python function "test_type_conversion_oid"
347+
test_type_conversion_oid
348+
--------------------------
349+
350+
(1 row)
351+
324352
CREATE FUNCTION test_type_conversion_text(x text) RETURNS text AS $$
325353
plpy.info(x, type(x))
326354
return x

‎src/pl/plpython/expected/plpython_types_3.out

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,34 @@ CONTEXT: PL/Python function "test_type_conversion_float8"
321321

322322
(1 row)
323323

324+
CREATE FUNCTION test_type_conversion_oid(x oid) RETURNS oid AS $$
325+
plpy.info(x, type(x))
326+
return x
327+
$$ LANGUAGE plpython3u;
328+
SELECT * FROM test_type_conversion_oid(100);
329+
INFO: (100, <class 'int'>)
330+
CONTEXT: PL/Python function "test_type_conversion_oid"
331+
test_type_conversion_oid
332+
--------------------------
333+
100
334+
(1 row)
335+
336+
SELECT * FROM test_type_conversion_oid(2147483649);
337+
INFO: (2147483649, <class 'int'>)
338+
CONTEXT: PL/Python function "test_type_conversion_oid"
339+
test_type_conversion_oid
340+
--------------------------
341+
2147483649
342+
(1 row)
343+
344+
SELECT * FROM test_type_conversion_oid(null);
345+
INFO: (None, <class 'NoneType'>)
346+
CONTEXT: PL/Python function "test_type_conversion_oid"
347+
test_type_conversion_oid
348+
--------------------------
349+
350+
(1 row)
351+
324352
CREATE FUNCTION test_type_conversion_text(x text) RETURNS text AS $$
325353
plpy.info(x, type(x))
326354
return x

‎src/pl/plpython/plpy_typeio.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static PyObject *PLyFloat_FromNumeric(PLyDatumToOb *arg, Datum d);
3939
staticPyObject*PLyInt_FromInt16(PLyDatumToOb*arg,Datumd);
4040
staticPyObject*PLyInt_FromInt32(PLyDatumToOb*arg,Datumd);
4141
staticPyObject*PLyLong_FromInt64(PLyDatumToOb*arg,Datumd);
42+
staticPyObject*PLyLong_FromOid(PLyDatumToOb*arg,Datumd);
4243
staticPyObject*PLyBytes_FromBytea(PLyDatumToOb*arg,Datumd);
4344
staticPyObject*PLyString_FromDatum(PLyDatumToOb*arg,Datumd);
4445
staticPyObject*PLyList_FromArray(PLyDatumToOb*arg,Datumd);
@@ -460,6 +461,9 @@ PLy_input_datum_func2(PLyDatumToOb *arg, Oid typeOid, HeapTuple typeTup)
460461
caseINT8OID:
461462
arg->func=PLyLong_FromInt64;
462463
break;
464+
caseOIDOID:
465+
arg->func=PLyLong_FromOid;
466+
break;
463467
caseBYTEAOID:
464468
arg->func=PLyBytes_FromBytea;
465469
break;
@@ -546,6 +550,12 @@ PLyLong_FromInt64(PLyDatumToOb *arg, Datum d)
546550
returnPyLong_FromLong(DatumGetInt64(d));
547551
}
548552

553+
staticPyObject*
554+
PLyLong_FromOid(PLyDatumToOb*arg,Datumd)
555+
{
556+
returnPyLong_FromUnsignedLong(DatumGetObjectId(d));
557+
}
558+
549559
staticPyObject*
550560
PLyBytes_FromBytea(PLyDatumToOb*arg,Datumd)
551561
{

‎src/pl/plpython/sql/plpython_types.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ SELECT * FROM test_type_conversion_float8(5000000000.5);
119119
SELECT*FROM test_type_conversion_float8(null);
120120

121121

122+
CREATEFUNCTIONtest_type_conversion_oid(xoid) RETURNSoidAS $$
123+
plpy.info(x, type(x))
124+
return x
125+
$$ LANGUAGE plpythonu;
126+
127+
SELECT*FROM test_type_conversion_oid(100);
128+
SELECT*FROM test_type_conversion_oid(2147483649);
129+
SELECT*FROM test_type_conversion_oid(null);
130+
131+
122132
CREATEFUNCTIONtest_type_conversion_text(xtext) RETURNStextAS $$
123133
plpy.info(x, type(x))
124134
return x

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp