Repository: duckdb/duckdb (language: python)

Issue:
list_max() and max() lose type information
### What happens?

For example:
```
D select list_max( [{'a':1}::JSON, [2]::JSON ]) as max;
┌─────────┐
│   max   │
│ varchar │
├─────────┤
│ {"a":1} │
└─────────┘

D select max(l) from (select unnest( [{'a':1}::JSON, [2]::JSON ]) as l);
┌─────────┐
│ max(l)  │
│ varchar │
├─────────┤
│ {"a":1} │
└─────────┘
```


Constrast the above with the DuckDB function max_list() defined as follows:
```
D create or replace function max_list(l) as (
  list_reduce(l, (acc, x) -> greatest(acc,x))
);

D select max_list( [ ['b']::JSON, ['a']::JSON ) as max;

┌───────┐
│  max  │
│ json  │
├───────┤
│ ["b"] │
└───────┘
```

### To Reproduce

```
select list_max( [{'a':1}::JSON, [2]::JSON ]) as max;
select max(l) from (select unnest( [{'a':1}::JSON, [2]::JSON ]) as l);
```

### OS:

MacOS

### DuckDB Version:

1.0, 1.1

### DuckDB Client:

CLI

### Hardware:

_No response_

### Full Name:

Peter

### Affiliation:

Koppstein

### What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a stable release

### Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set

### Did you include all code required to reproduce the issue?

- [X] Yes, I have

### Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

- [X] Yes, I have


Discussion / hints:

Fix patch:
diff --git a/src/core_functions/aggregate/distributive/minmax.cpp b/src/core_functions/aggregate/distributive/minmax.cpp
index dba09e5aa0a8..9642da1561a7 100644
--- a/src/core_functions/aggregate/distributive/minmax.cpp
+++ b/src/core_functions/aggregate/distributive/minmax.cpp
@@ -315,8 +315,8 @@ static AggregateFunction GetMinMaxOperator(const LogicalType &type) {
 	auto internal_type = type.InternalType();
 	switch (internal_type) {
 	case PhysicalType::VARCHAR:
-		return AggregateFunction::UnaryAggregateDestructor<MinMaxStringState, string_t, string_t, OP_STRING>(type.id(),
-		                                                                                                     type.id());
+		return AggregateFunction::UnaryAggregateDestructor<MinMaxStringState, string_t, string_t, OP_STRING>(type,
+		                                                                                                     type);
 	case PhysicalType::LIST:
 	case PhysicalType::STRUCT:
 	case PhysicalType::ARRAY:


Test patch:
diff --git a/test/sql/aggregate/aggregates/test_minmax_14145.test b/test/sql/aggregate/aggregates/test_minmax_14145.test
new file mode 100644
index 000000000000..635c7894a4fa
--- /dev/null
+++ b/test/sql/aggregate/aggregates/test_minmax_14145.test
@@ -0,0 +1,14 @@
+# name: test/sql/aggregate/aggregates/test_minmax_14145.test
+# description: Test minmax aggregation issue 14145
+# group: [aggregates]
+
+require json
+
+statement ok
+PRAGMA enable_verification
+
+query IIIIII
+DESCRIBE SELECT max(l) from (select unnest( [{'a':1}::JSON, [2]::JSON ]) as l);
+----
+max(l)	JSON	YES	NULL	NULL	NULL
+