Skip to content
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

Unable to execute union with order by expression #185

Closed
1 of 3 tasks
o1egl opened this issue Dec 3, 2019 · 0 comments
Closed
1 of 3 tasks

Unable to execute union with order by expression #185

o1egl opened this issue Dec 3, 2019 · 0 comments

Comments

@o1egl
Copy link
Contributor

o1egl commented Dec 3, 2019

Currently when I try to scan sql queries with union and order statements I receive goqu: unable to execute query did you use goqu.Database#From to create the dataset. Sql queries without order statement work as expected.

To Reproduce

db := goqu.New("postgres", conn)
sql := db.Select("id").From("table").Order(goqu.C("id").Asc()).
    Union(
        db.Select("id").From("table").Order(goqu.C("id").Asc()),
    )

var i []int
if err := sql.ScanValsContext(ctx, &i); err != nil {
    panic(err)
}

Dialect:

  • postgres
  • mysql
  • sqlite3

Additional context
Currently I have found a workaround by wrapping the entire query with a select statement

db := goqu.New("postgres", conn)
sql := db.Select("id").From("table").Order(goqu.C("id").Asc()).
    Union(
        db.Select("id").From("table").Order(goqu.C("id").Asc()),
    )
// workaround
sql = db.Select("*").From(sql)
var i []int
if err := sql.ScanValsContext(ctx, &i); err != nil {
    panic(err)
}
doug-martin pushed a commit that referenced this issue Dec 6, 2019
doug-martin pushed a commit that referenced this issue Dec 6, 2019
doug-martin pushed a commit that referenced this issue Dec 6, 2019
doug-martin pushed a commit that referenced this issue Dec 6, 2019
doug-martin pushed a commit that referenced this issue Dec 6, 2019
doug-martin added a commit that referenced this issue Dec 6, 2019
@doug-martin doug-martin mentioned this issue Dec 7, 2019
@doug-martin doug-martin added this to the v9.5.1 milestone Dec 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants