Skip to content

GROUP BY on field of type INTEGER sometimes loses type #536

Closed

Description

@CBke
create table data( id INTEGER PRIMARY KEY, grp INTEGER);
insert into data select range._ as id , range._ % 3 as grp  from RANGE(0,9)as range;
select id, id +1 from data group by id;
select a.id, a.id +1, CAST(a.id AS INTEGER) +1 from data as a, data as b where a.id < b.id and a.grp = b.grp group by a.id

Activity

  1. CBke commented on Jan 15, 2016

    @CBke
    Author

    SELECT id, id + 1 FROM data GROUP BY id

    # id id + 1
    1 0 1
    2 1 2
    3 2 3
    4 3 4
    5 4 5
    6 5 6
    7 6 7
    8 7 8
    9 8 9
    10 9 10

    SELECT a.id, a.id + 1, CONVERT(INT,a.id) + 1 FROM data AS a,data AS b WHERE a.id < b.id AND a.grp = b.grp GROUP BY a.id

    # id a.id + 1 CONVERT(INT,a.id) + 1
    1 0 NULL 1
    2 1 NULL 1
    3 2 NULL 1
    4 3 NULL 1
    5 4 NULL 1
    6 5 NULL 1
    7 6 NULL 1

    expected result

    # id a.id + 1 CONVERT(INT,a.id) + 1
    1 0 1 1
    2 1 2 2
    3 2 3 3
    4 3 4 4
    5 4 5 5
    6 5 6 6
    7 6 7 7
  2. agershun commented on Jan 15, 2016

    @agershun
    Member

    Please use variables without table prefix (at current moment it gives correct answer):

        select a.id, (id +1), CAST(id AS INTEGER) +1 from data as a, data as b 
                  where a.id < b.id and a.grp = b.grp group by a.id

    I will check details later.

  3. added a commit that references this issue on Dec 2, 2025
    75772b9
  4. mathiasrw commented on Dec 6, 2025

    @mathiasrw
    Member

    Fix released in v4.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions