From a557a196aa8fd338abade699174915f7e18f49b9 Mon Sep 17 00:00:00 2001 From: Hanefi Onaldi Date: Wed, 7 Sep 2022 06:49:24 +0300 Subject: [PATCH] Add tests for numeric with scale greater than precision --- src/test/regress/bin/normalize.sed | 1 + src/test/regress/expected/pg15.out | 47 +++++++++++++++++++++++++++++- src/test/regress/sql/pg15.sql | 13 +++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/test/regress/bin/normalize.sed b/src/test/regress/bin/normalize.sed index 97d9d5da4..531029bcd 100644 --- a/src/test/regress/bin/normalize.sed +++ b/src/test/regress/bin/normalize.sed @@ -217,6 +217,7 @@ s/^(ERROR: child table is missing constraint "\w+)_([0-9])+"/\1_xxxxxx"/g # normalize long table shard name errors for alter_table_set_access_method and alter_distributed_table s/^(ERROR: child table is missing constraint "\w+)_([0-9])+"/\1_xxxxxx"/g s/^(DEBUG: the name of the shard \(abcde_01234567890123456789012345678901234567890_f7ff6612)_([0-9])+/\1_xxxxxx/g +s/^(ERROR: cannot distribute relation: numeric_negative_scale)_([0-9]+)/\1_xxxxxx"/g # normalize long index name errors for multi_index_statements s/^(ERROR: The index name \(test_index_creation1_p2020_09_26)_([0-9])+_(tenant_id_timeperiod_idx)/\1_xxxxxx_\3/g diff --git a/src/test/regress/expected/pg15.out b/src/test/regress/expected/pg15.out index a91cdde2f..879c10137 100644 --- a/src/test/regress/expected/pg15.out +++ b/src/test/regress/expected/pg15.out @@ -410,6 +410,12 @@ HINT: To remove the local data, run: SELECT truncate_local_data_after_distribut (1 row) +-- Verify that we can not change the distribution column to the numeric column +SELECT alter_distributed_table('numeric_negative_scale', + distribution_column := 'numeric_column'); +NOTICE: creating a new table for pg15.numeric_negative_scale +ERROR: cannot distribute relation: numeric_negative_scale_xxxxxx" +DETAIL: Distribution column must not use numeric type with negative scale SELECT * FROM numeric_negative_scale ORDER BY 1,2; numeric_column | orig_value --------------------------------------------------------------------- @@ -420,6 +426,45 @@ SELECT * FROM numeric_negative_scale ORDER BY 1,2; 120 | 115 (5 rows) +-- verify that numeric types with scale greater than precision are also ok +-- a precision of 2, and scale of 3 means that all the numbers should be less than 10^-1 and of the form 0,0XY +CREATE TABLE numeric_scale_gt_precision(numeric_column numeric(2,3)); +SELECT * FROM create_distributed_table('numeric_scale_gt_precision','numeric_column'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +INSERT INTO numeric_scale_gt_precision SELECT x FROM generate_series(0.01234, 0.09, 0.005) x; +-- verify that we store only 2 digits, and discard the rest of them. +SELECT * FROM numeric_scale_gt_precision ORDER BY 1; + numeric_column +--------------------------------------------------------------------- + 0.012 + 0.017 + 0.022 + 0.027 + 0.032 + 0.037 + 0.042 + 0.047 + 0.052 + 0.057 + 0.062 + 0.067 + 0.072 + 0.077 + 0.082 + 0.087 +(16 rows) + +-- verify we can route queries to the right shards +SELECT * FROM numeric_scale_gt_precision WHERE numeric_column=0.027; + numeric_column +--------------------------------------------------------------------- + 0.027 +(1 row) + -- test new regex functions -- print order comments that contain the word `fluffily` at least twice SELECT o_comment FROM public.orders WHERE regexp_count(o_comment, 'FluFFily', 1, 'i')>=2 ORDER BY 1; @@ -510,4 +555,4 @@ SELECT count(*)=100 FROM copy_test2; -- Clean up \set VERBOSITY terse DROP SCHEMA pg15 CASCADE; -NOTICE: drop cascades to 11 other objects +NOTICE: drop cascades to 13 other objects diff --git a/src/test/regress/sql/pg15.sql b/src/test/regress/sql/pg15.sql index c01d4d63d..11942a4ce 100644 --- a/src/test/regress/sql/pg15.sql +++ b/src/test/regress/sql/pg15.sql @@ -252,9 +252,22 @@ INSERT into numeric_negative_scale SELECT x,x FROM generate_series(111, 115) x; SELECT create_distributed_table('numeric_negative_scale','numeric_column'); -- However, we can distribute by other columns SELECT create_distributed_table('numeric_negative_scale','orig_value'); +-- Verify that we can not change the distribution column to the numeric column +SELECT alter_distributed_table('numeric_negative_scale', + distribution_column := 'numeric_column'); SELECT * FROM numeric_negative_scale ORDER BY 1,2; +-- verify that numeric types with scale greater than precision are also ok +-- a precision of 2, and scale of 3 means that all the numbers should be less than 10^-1 and of the form 0,0XY +CREATE TABLE numeric_scale_gt_precision(numeric_column numeric(2,3)); +SELECT * FROM create_distributed_table('numeric_scale_gt_precision','numeric_column'); +INSERT INTO numeric_scale_gt_precision SELECT x FROM generate_series(0.01234, 0.09, 0.005) x; + +-- verify that we store only 2 digits, and discard the rest of them. +SELECT * FROM numeric_scale_gt_precision ORDER BY 1; +-- verify we can route queries to the right shards +SELECT * FROM numeric_scale_gt_precision WHERE numeric_column=0.027; -- test new regex functions -- print order comments that contain the word `fluffily` at least twice