From: Peter Eisentraut Date: Wed, 4 Jan 2017 17:00:00 +0000 (-0500) Subject: Add more tests for money type X-Git-Tag: REL_10_BETA1~1100 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=09e35315ccafb83c52da2e0fd6a0a9be410ce6a4;p=postgresql Add more tests for money type Add tests for functions currently not covered at all. Reviewed-by: Pavel Stehule --- diff --git a/src/test/regress/expected/money.out b/src/test/regress/expected/money.out index 5695f87500..a05fdd9f42 100644 --- a/src/test/regress/expected/money.out +++ b/src/test/regress/expected/money.out @@ -27,18 +27,84 @@ SELECT m - '123.45' FROM money_data; -$0.45 (1 row) +SELECT m / '2'::money FROM money_data; + ?column? +---------- + 61.5 +(1 row) + SELECT m * 2 FROM money_data; ?column? ---------- $246.00 (1 row) +SELECT 2 * m FROM money_data; + ?column? +---------- + $246.00 +(1 row) + SELECT m / 2 FROM money_data; ?column? ---------- $61.50 (1 row) +SELECT m * 2::int2 FROM money_data; + ?column? +---------- + $246.00 +(1 row) + +SELECT 2::int2 * m FROM money_data; + ?column? +---------- + $246.00 +(1 row) + +SELECT m / 2::int2 FROM money_data; + ?column? +---------- + $61.50 +(1 row) + +SELECT m * 2::float8 FROM money_data; + ?column? +---------- + $246.00 +(1 row) + +SELECT 2::float8 * m FROM money_data; + ?column? +---------- + $246.00 +(1 row) + +SELECT m / 2::float8 FROM money_data; + ?column? +---------- + $61.50 +(1 row) + +SELECT m * 2::float4 FROM money_data; + ?column? +---------- + $246.00 +(1 row) + +SELECT 2::float4 * m FROM money_data; + ?column? +---------- + $246.00 +(1 row) + +SELECT m / 2::float4 FROM money_data; + ?column? +---------- + $61.50 +(1 row) + -- All true SELECT m = '$123.00' FROM money_data; ?column? @@ -275,7 +341,7 @@ SELECT '92233720368547758.075'::money; ERROR: value "92233720368547758.075" is out of range for type money LINE 1: SELECT '92233720368547758.075'::money; ^ --- Cast int4/int8 to money +-- Cast int4/int8/numeric to money SELECT 1234567890::money; money ------------------- @@ -318,6 +384,12 @@ SELECT 12345678901234567::int8::money; $12,345,678,901,234,567.00 (1 row) +SELECT 12345678901234567::numeric::money; + money +---------------------------- + $12,345,678,901,234,567.00 +(1 row) + SELECT (-1234567890)::int4::money; money -------------------- @@ -330,3 +402,22 @@ SELECT (-12345678901234567)::int8::money; -$12,345,678,901,234,567.00 (1 row) +SELECT (-12345678901234567)::numeric::money; + money +----------------------------- + -$12,345,678,901,234,567.00 +(1 row) + +-- Cast from money +SELECT '12345678901234567'::money::numeric; + numeric +---------------------- + 12345678901234567.00 +(1 row) + +SELECT '-12345678901234567'::money::numeric; + numeric +----------------------- + -12345678901234567.00 +(1 row) + diff --git a/src/test/regress/sql/money.sql b/src/test/regress/sql/money.sql index 561ccb527f..9e89e32d77 100644 --- a/src/test/regress/sql/money.sql +++ b/src/test/regress/sql/money.sql @@ -9,8 +9,19 @@ SELECT * FROM money_data; SELECT m + '123' FROM money_data; SELECT m + '123.45' FROM money_data; SELECT m - '123.45' FROM money_data; +SELECT m / '2'::money FROM money_data; SELECT m * 2 FROM money_data; +SELECT 2 * m FROM money_data; SELECT m / 2 FROM money_data; +SELECT m * 2::int2 FROM money_data; +SELECT 2::int2 * m FROM money_data; +SELECT m / 2::int2 FROM money_data; +SELECT m * 2::float8 FROM money_data; +SELECT 2::float8 * m FROM money_data; +SELECT m / 2::float8 FROM money_data; +SELECT m * 2::float4 FROM money_data; +SELECT 2::float4 * m FROM money_data; +SELECT m / 2::float4 FROM money_data; -- All true SELECT m = '$123.00' FROM money_data; @@ -83,7 +94,7 @@ SELECT '92233720368547758.08'::money; SELECT '-92233720368547758.085'::money; SELECT '92233720368547758.075'::money; --- Cast int4/int8 to money +-- Cast int4/int8/numeric to money SELECT 1234567890::money; SELECT 12345678901234567::money; SELECT (-12345)::money; @@ -91,5 +102,11 @@ SELECT (-1234567890)::money; SELECT (-12345678901234567)::money; SELECT 1234567890::int4::money; SELECT 12345678901234567::int8::money; +SELECT 12345678901234567::numeric::money; SELECT (-1234567890)::int4::money; SELECT (-12345678901234567)::int8::money; +SELECT (-12345678901234567)::numeric::money; + +-- Cast from money +SELECT '12345678901234567'::money::numeric; +SELECT '-12345678901234567'::money::numeric;