Skip to Main Content
  • Questions
  • MAX aggregation function shows different results when partitioned

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Pablo.

Asked: March 27, 2019 - 6:48 pm UTC

Last updated: April 02, 2019 - 10:09 am UTC

Version: 12.1.0.2.0

Viewed 1000+ times

You Asked

Hi everyone, I'm getting strange results from a query.

I have a table list partitioned by id, when I execute this :

select max(col1) from table where id=100;


it returns the value 'A1'. Then I execute the following (keep in mind that partName is the name of the partition for id=100):

select max(col1) from table (partName);


and it returns 'B1'

The correct value in partition partName is B1, if I
select id from table where col1='A1'
it returns the correct value (500).

Do you know of any bug on the MAX function using partitioned tables that could cause this?

Thanks!

and Chris said...

I can't reproduce this or find any obviously related bugs:

create table t (
  c1 int, 
  c2 int
) partition by list ( c1 ) (
  partition p1 values ( 1 ), 
  partition p2 values ( 2 ),
  partition p3 values ( 3 ), 
  partition p4 values ( 4 )
);

insert into t 
with rws as (
  select mod ( level, 4 ) + 1, level x 
  from   dual
  connect by level <= 10
)
  select * from rws;
  
select max ( c2 ) from t
where  c1 = 1;

MAX(C2)   
        8 

select max ( c2 ) 
from   t partition ( p1 );

MAX(C2)   
        8 


If you want us to look into this further, we'll need a complete test-case:

- create table
- insert into
- selects

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Ugly question

A reader, March 28, 2019 - 6:32 pm UTC

And what if table(partname) is a table function not an object of table type?

Also select whatever from "table" . Do you really named your table table? Tablbo tablbo.

see no evil

Racer I., April 01, 2019 - 12:55 pm UTC

Hi,

We had something like this once because of partition exchange with without validation;

https://community.oracle.com/thread/973159

regards,
Chris Saxon
April 02, 2019 - 10:09 am UTC

Yep, that could be the cause.

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.