New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid SQL generated for SelectStatements and subqueries. #1587

Closed
weiznich opened this Issue Mar 5, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@weiznich
Contributor

weiznich commented Mar 5, 2018

Setup

Versions

  • Diesel: master (ac30743) / 1.1
  • Database: postgres

Feature Flags

  • diesel: postgres

Problem Description

Without a explicit select clause diesel will generate invalid sql when using normal select statement as subquery in a IN clause.
This does not happen with BoxedSelectStatements.

What are you trying to accomplish?

table!{
    users{
       id -> Integer,
       name -> Text,
    }
}

table! {
    posts {
        id -> Integer,
        user_id -> Integer,
    }
}

fn test(conn: &PgConnection) {
    let subquery = users::table.filter(users::id.eq(1));
    let query = posts::table.filter(posts::user_id.eq_any(subquery));
    query.execute(conn).unwrap();
}

What is the expected output?

A compiler error.

What is the actual output?

The program compiles fine, but errors with a invalid query at runtime.
DatabaseError(__Unknown, "subquery has too many columns")

Are you seeing any additional errors?

No

Steps to reproduce

@weiznich weiznich added the bug label Mar 5, 2018

@sgrif sgrif added this to the 1.2 milestone Mar 5, 2018

sgrif added a commit that referenced this issue Apr 5, 2018

Tighten bounds on select statements used as a subselect
We were accidentally allowing them to coerce to any SQL type.
Fixes #1587.

@sgrif sgrif closed this in #1616 Apr 5, 2018

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