mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
to_char(float4/8): zero pad to specified length
Previously, zero padding was limited to the internal length, rather than the specified length. This allows it to match to_char(int/numeric), which always padded to the specified length. Regression tests added. BACKWARD INCOMPATIBILITY
This commit is contained in:
@ -1499,3 +1499,73 @@ select * from generate_series(1::numeric, 3::numeric) i, generate_series(1,5,i)
|
||||
3 | 4
|
||||
(10 rows)
|
||||
|
||||
--
|
||||
-- Test code path for high-precision output
|
||||
--
|
||||
SELECT to_char(float8 '99999999999', '9999999999999999D99999999');
|
||||
to_char
|
||||
----------------------------
|
||||
99999999999.00000000
|
||||
(1 row)
|
||||
|
||||
SELECT to_char(float8 '99999999999', '9999999999999999D' || repeat('9', 1000));
|
||||
to_char
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
99999999999.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
(1 row)
|
||||
|
||||
SELECT to_char(float8 '1e9','999999999999999999999D9');
|
||||
to_char
|
||||
--------------------------
|
||||
1000000000.0
|
||||
(1 row)
|
||||
|
||||
SELECT to_char(float8 '1e20','999999999999999999999D9');
|
||||
to_char
|
||||
--------------------------
|
||||
100000000000000000000.0
|
||||
(1 row)
|
||||
|
||||
SELECT to_char(1e20, '999999999999999999999D9');
|
||||
to_char
|
||||
--------------------------
|
||||
100000000000000000000.0
|
||||
(1 row)
|
||||
|
||||
SELECT to_char(float8 '1.123456789123456789', '9.' || repeat('9', 55));
|
||||
to_char
|
||||
------------------------------------------------------------
|
||||
1.1234567891234500000000000000000000000000000000000000000
|
||||
(1 row)
|
||||
|
||||
SELECT to_char(float8 '1999999999999999999999999999999999999999999999.123456789123456789',
|
||||
repeat('9', 50) || '.' || repeat('9', 50));
|
||||
to_char
|
||||
--------------------------------------------------------------------------------------------------------
|
||||
1999999999999990000000000000000000000000000000.00000000000000000000000000000000000000000000000000
|
||||
(1 row)
|
||||
|
||||
SELECT to_char(float8 '0.1', '9D' || repeat('9', 1000));
|
||||
to_char
|
||||
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
.1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
(1 row)
|
||||
|
||||
SELECT to_char(int4 '1', '9D' || repeat('9', 1000) || 'EEEE');
|
||||
to_char
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+00
|
||||
(1 row)
|
||||
|
||||
SELECT to_char(float4 '1', '9D' || repeat('9', 1000) || 'EEEE');
|
||||
to_char
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+00
|
||||
(1 row)
|
||||
|
||||
SELECT to_char(float8 '1', '9D' || repeat('9', 1000) || 'EEEE');
|
||||
to_char
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+00
|
||||
(1 row)
|
||||
|
||||
|
@ -1806,7 +1806,7 @@ SELECT to_char(SUM(n::float8) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND 1 FO
|
||||
FROM (VALUES(1,1e20),(2,1)) n(i,n);
|
||||
to_char
|
||||
--------------------------
|
||||
100000000000000000000
|
||||
100000000000000000000.0
|
||||
1.0
|
||||
(2 rows)
|
||||
|
||||
|
@ -858,3 +858,20 @@ select (i / (10::numeric ^ 131071))::numeric(1,0)
|
||||
select * from generate_series(1::numeric, 3::numeric) i, generate_series(i,3) j;
|
||||
select * from generate_series(1::numeric, 3::numeric) i, generate_series(1,i) j;
|
||||
select * from generate_series(1::numeric, 3::numeric) i, generate_series(1,5,i) j;
|
||||
|
||||
--
|
||||
-- Test code path for high-precision output
|
||||
--
|
||||
|
||||
SELECT to_char(float8 '99999999999', '9999999999999999D99999999');
|
||||
SELECT to_char(float8 '99999999999', '9999999999999999D' || repeat('9', 1000));
|
||||
SELECT to_char(float8 '1e9','999999999999999999999D9');
|
||||
SELECT to_char(float8 '1e20','999999999999999999999D9');
|
||||
SELECT to_char(1e20, '999999999999999999999D9');
|
||||
SELECT to_char(float8 '1.123456789123456789', '9.' || repeat('9', 55));
|
||||
SELECT to_char(float8 '1999999999999999999999999999999999999999999999.123456789123456789',
|
||||
repeat('9', 50) || '.' || repeat('9', 50));
|
||||
SELECT to_char(float8 '0.1', '9D' || repeat('9', 1000));
|
||||
SELECT to_char(int4 '1', '9D' || repeat('9', 1000) || 'EEEE');
|
||||
SELECT to_char(float4 '1', '9D' || repeat('9', 1000) || 'EEEE');
|
||||
SELECT to_char(float8 '1', '9D' || repeat('9', 1000) || 'EEEE');
|
||||
|
Reference in New Issue
Block a user