Skip to content

Commit

Permalink
Merge pull request #138 from Mytherin/issue136
Browse files Browse the repository at this point in the history
Fix #136 - correctly deal with decimals that have many leading zeros
  • Loading branch information
Mytherin authored Nov 28, 2023
2 parents 0834101 + d34ecbc commit cd6d147
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/include/postgres_binary_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ struct PostgresBinaryReader {
auto fractional_power_correction = fractional_power - config.scale;
D_ASSERT(fractional_power_correction < 20);
fractional_part = 0;
for (auto i = config.weight + 1; i < config.ndigits; i++) {
for (int32_t i = MaxValue<int32_t>(0, config.weight + 1); i < config.ndigits; i++) {
if (i + 1 < config.ndigits) {
// more digits remain - no need to compensate yet
fractional_part *= NBASE;
Expand Down
27 changes: 27 additions & 0 deletions test/all_pg_types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,30 @@ INSERT INTO mixed_arrays VALUES (
INSERT INTO mixed_arrays VALUES (
ARRAY[1, 2, 3]
);

-- Issue #136 - Inconsistent results from querying postgres numeric columns
create TABLE public_amounts (
id bigint NOT NULL,
rate numeric NOT NULL
);
insert into public_amounts values
(1, 0.67),
(2, 0.067),
(3, 0.0067),
(4, 0.00067),
(5, 0.000067),
(6, 0.0000067),
(7, 0.00000067),
(8, 0.000000067),
(9, 0.0000000067),
(10, 0.00000000067),
(11, 0.000000000067),
(12, 0.0000000000067),
(13, 0.00000000000067),
(14, 0.000000000000067),
(15, 0.0000000000000067),
(16, 0.00000000000000067),
(17, 0.000000000000000067),
(18, 0.0000000000000000067),
(19, 0.00000000000000000067),
(20, 0.000000000000000000067);
37 changes: 37 additions & 0 deletions test/sql/storage/bug136.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# name: test/sql/storage/bug136.test
# description: Issue #136 - Inconsistent results from querying postgres numeric columns
# group: [storage]

require postgres_scanner

require-env POSTGRES_TEST_DATABASE_AVAILABLE

statement ok
ATTACH 'dbname=postgresscanner' AS s (TYPE POSTGRES)

statement ok
USE s;

query II
SELECT * FROM public_amounts ORDER BY id
----
1 0.67
2 0.067
3 0.0067
4 0.00067
5 0.000067
6 0.0000067
7 0.00000067
8 0.000000067
9 0.0000000067
10 0.00000000067
11 0.000000000067
12 0.0000000000067
13 0.00000000000067
14 0.000000000000067
15 0.0000000000000067
16 0.00000000000000067
17 0.000000000000000067
18 0.0000000000000000067
19 0.00000000000000000067
20 0.000000000000000000067

0 comments on commit cd6d147

Please sign in to comment.