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

Invalid sql when using raw query #2672

Open
tzaavi opened this issue Dec 22, 2022 · 5 comments
Open

Invalid sql when using raw query #2672

tzaavi opened this issue Dec 22, 2022 · 5 comments

Comments

@tzaavi
Copy link

tzaavi commented Dec 22, 2022

Version: 4.6.0
Module: quill-jdbc-zio
Database: mysql

Getting invalid sql with raw query. for example this query

val q = quote {
   sql"""select id, name from users""".as[Query[(Int, Int)]]
}
val res = run(q)

Expected behavior

According to documentation is should generate this valid sql

SELECT x._1, x._2 FROM (SELECT id AS "_1", name AS "_2" FROM users) x

Actual behavior

but it generate this invalid sql

select x.1 as _1, x.2 as _2 from (select id, name from users) x

this create error: Unknown column 'x.1' in 'field list'

Workaround

the only way I could make it work is with this query

val q = quote {
   sql"""select id as "1", name as "2" from users""".as[Query[(Int, Int)]]
}
val res = run(q)

@getquill/maintainers

@fancellu
Copy link

fancellu commented Feb 3, 2023

Are raw queries still broken? I ask as I'm doing similar, for a query that runs fine in raw jdbc, but complains
Invalid object on the table name with a rawQuery.
i.e.

    val top2Messages = quote {
      sql"SELECT TOP (2) message FROM xyz.in".as[Query[String]]
    }
    println(top2Messages.toString())
    val ret=ctx.run(top2Messages)
    println(ret)

I get
sql"SELECT TOP (2) message FROM xyz.in"

And that same query is fine in raw jdbc

@Ellzord
Copy link

Ellzord commented Jul 31, 2023

This is still happening for me on 4.6.1 (postgres + zio), it's tuples specifically so single Query[String] is fine.

The workaround is to name the fields _1 not 1 from above.

@tnielens
Copy link

tnielens commented Oct 3, 2023

Seems still broken in 4.7.3. I'm using quill-cassandra-zio. The workarounds suggested precedently don't work for me for both version 4.6.1 and 4.7.3.

@guizmaii
Copy link
Member

guizmaii commented Oct 3, 2023

What about using a case class to replace the Tuple as a workaround?

final case class Result(id: Int, name: Int)
val q = quote {
   sql"""select id, name from users""".as[Query[Result]]
}
val res = run(q)

?

@tnielens
Copy link

tnielens commented Oct 3, 2023

Hi @guizmaii 👋 , thanks for quick response.
I did try that as well without success. It's the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants