Skip to content

Use of window functions wraps other columns with Option #2874

@BTOdell

Description

@BTOdell

Bug Description

When using Window Functions and the OVER (...) syntax, Rust/SQLx starts wrapping all of the other columns/fields with Option<T>. In my specific example, I'm using ROW_NUMBER() which is a non-aggregating function, so the other columns will never be NULL.

My guess is that SQLx isn't responsible for parsing the SQL query and is just using what the database is returning back, but maybe SQLx is misinterpreting something from the database or not handling a certain condition properly.

My current workaround is to just throw some unwrap() calls on all the columns that should be non-null, but I'd really prefer to avoid that.

Minimal Reproduction

SELECT
    user.username,
    user.elo,
    ROW_NUMBER() OVER (ORDER BY user.elo DESC, user.most_recent_match DESC, user.id ASC) AS `rank`
FROM user
ORDER BY rank

If I run this query using the query! macro and fetch_all, the user records have username as an Option<String> instead of just a String.

Info

  • SQLx version: 0.7.2
  • SQLx features enabled: mysql, runtime-tokio, time
  • Database server and version: MariaDB 11.1.2 (docker)
  • Operating system: Windows host, Linux (ubuntu-jammy) MariaDB docker container
  • rustc --version: 1.73.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbug:dbInvolves a bug in the database serverdb:mysqlRelated to MySQL

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions