Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #136 - correctly deal with decimals that have many leading zeros #138

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading