mirror of
https://github.com/postgres/postgres.git
synced 2025-12-12 02:37:31 +03:00
PL/Python: Convert numeric to Decimal
The old implementation converted PostgreSQL numeric to Python float, which was always considered a shortcoming. Now numeric is converted to the Python Decimal object. Either the external cdecimal module or the standard library decimal module are supported. From: Szymon Guz <mabewlun@gmail.com> From: Ronan Dunklau <rdunklau@gmail.com> Reviewed-by: Steve Singer <steve@ssinger.info>
This commit is contained in:
@@ -86,14 +86,19 @@ SELECT * FROM test_type_conversion_int8(null);
|
||||
|
||||
|
||||
CREATE FUNCTION test_type_conversion_numeric(x numeric) RETURNS numeric AS $$
|
||||
plpy.info(x, type(x))
|
||||
# print just the class name, not the type, to avoid differences
|
||||
# between decimal and cdecimal
|
||||
plpy.info(x, x.__class__.__name__)
|
||||
return x
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
/* The current implementation converts numeric to float. */
|
||||
SELECT * FROM test_type_conversion_numeric(100);
|
||||
SELECT * FROM test_type_conversion_numeric(-100);
|
||||
SELECT * FROM test_type_conversion_numeric(100.0);
|
||||
SELECT * FROM test_type_conversion_numeric(100.00);
|
||||
SELECT * FROM test_type_conversion_numeric(5000000000.5);
|
||||
SELECT * FROM test_type_conversion_numeric(1234567890.0987654321);
|
||||
SELECT * FROM test_type_conversion_numeric(-1234567890.0987654321);
|
||||
SELECT * FROM test_type_conversion_numeric(null);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user