Skip to content

Commit 3d4b920

Browse files
committed
More correct
1 parent 6a0cd0a commit 3d4b920

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

pgdog/src/backend/pool/connection/aggregate.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ impl<'a> Accumulator<'a> {
4646
target,
4747
datum: Datum::Bigint(0),
4848
},
49-
AggregateFunction::Max => Accumulator {
50-
target,
51-
datum: Datum::Bigint(i64::MIN),
52-
},
53-
AggregateFunction::Min => Accumulator {
54-
target,
55-
datum: Datum::Bigint(i64::MAX),
56-
},
5749
_ => Accumulator {
5850
target,
5951
datum: Datum::Null,
@@ -68,12 +60,20 @@ impl<'a> Accumulator<'a> {
6860
match self.target.function() {
6961
AggregateFunction::Count => self.datum = self.datum.clone() + column.value,
7062
AggregateFunction::Max => {
71-
if self.datum < column.value {
63+
if !self.datum.is_null() {
64+
if self.datum < column.value {
65+
self.datum = column.value;
66+
}
67+
} else {
7268
self.datum = column.value;
7369
}
7470
}
7571
AggregateFunction::Min => {
76-
if self.datum > column.value {
72+
if !self.datum.is_null() {
73+
if self.datum > column.value {
74+
self.datum = column.value;
75+
}
76+
} else {
7777
self.datum = column.value;
7878
}
7979
}

pgdog/src/net/messages/data_types/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ impl Add for Datum {
7878
(SmallInt(a), SmallInt(b)) => SmallInt(a + b),
7979
(Interval(a), Interval(b)) => Interval(a + b),
8080
(Numeric(a), Numeric(b)) => Numeric(a + b),
81+
(Datum::Null, b) => b,
82+
(a, Datum::Null) => a,
8183
_ => Datum::Null, // Might be good to raise an error.
8284
}
8385
}
@@ -103,6 +105,10 @@ impl Datum {
103105
_ => Ok(Datum::Null),
104106
}
105107
}
108+
109+
pub fn is_null(&self) -> bool {
110+
matches!(self, Datum::Null)
111+
}
106112
}
107113

108114
/// PostgreSQL data types.

0 commit comments

Comments
 (0)