Skip to content

Window function only respects first PARTITION column #5209

@henneberger

Description

@henneberger

I noticed that when using a window query with multiple columns in the PARTITION BY clause, only the first column is respected and the rest are discard.

Example query:

SELECT f_name, l_name, city, ROW_NUMBER() OVER (PARTITION BY f_name, l_name ORDER by city DESC) rn 
FROM (VALUES ROW('frank','m','ny'), 
             ROW('frank','m','ny'), 
             ROW('daniel','h','dc'), 
             ROW('frank','g','ny')) AS t(f_name, l_name, city) 
ORDER BY f_name, l_name, city

Expected results: The ROW_NUMBER() function should partition the rows based on both the f_name and l_name columns.

+--------+--------+------+----+
| f_name | l_name | city | rn |
+--------+--------+------+----+
| daniel | h      | dc   | 1  |
| frank  | g      | ny   | 1  |
| frank  | m      | ny   | 1  |
| frank  | m      | ny   | 2  |
+--------+--------+------+----+

Actual results: The ROW_NUMBER() function only partitions the rows based on the f_name column, ignoring the l_name column.

+--------+--------+------+----+
| f_name | l_name | city | rn |
+--------+--------+------+----+
| daniel | h      | dc   | 1  |
| frank  | g      | ny   | 1  |
| frank  | m      | ny   | 2  |
| frank  | m      | ny   | 3  |
+--------+--------+------+----+

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingsqlIssue with SQL

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions