Skip to content

list_max() and max() lose type information #14145

@pkoppstein

Description

@pkoppstein

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?

  • Yes, I have

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

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions