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

Insert query not working #1104

Closed
gbogard opened this issue May 20, 2018 · 4 comments
Closed

Insert query not working #1104

gbogard opened this issue May 20, 2018 · 4 comments
Labels

Comments

@gbogard
Copy link

gbogard commented May 20, 2018

Version: 2.4.2
Module: quill-jdbc
Database: postgres

Expected behavior

I'm trying to insert a new row into a table. My code looks like this

Future {
      run {
        quote {
          decks.insert(lift(deck)).returning(_.id)
        }
      }
    }

Actual behavior

I'm noticing two issues :
First of all, this code gets compiled as a "Dynamic query", but I don't see why it couldn't be compile as a static quotation. I've used similar code in other places in the project and some of them get compiled as static quotations

Second of all, and most importantly, when actually running the code, the insert query is wrong. Here's what I get :

19:21:25.474 [blocking-IO-1] DEBUG io.getquill.context.jdbc.JdbcContext - INSERT INTO courses.decks (name,owner_type,owner_id,language,description,category_id,is_premium,visibility,created_at,updated_at) VALUES (name, owner_type, owner_id, language, description, category_id, is_premium, visibility, created_at, updated_at)
[error] knoko - ERROR: column "name" does not exist
  Indice : There is a column named "name" in table "decks", but it cannot be referenced from this part of the query.
  Position : 139

Here we can see that instead of placing the acual values in the VALUES part of the query, quill repeats the column names, resulting in a postgres error

I have no idea why it does that for this particular case class and not all of them

How to reproduce

See the scastie

@getquill/maintainers

@mosyp
Copy link
Collaborator

mosyp commented May 20, 2018

Please provide reproducible example using scastie. The information that you provided is insufficient.

@gbogard
Copy link
Author

gbogard commented May 21, 2018

Sure! I made a scastie like you asked. We can see in the scastie that the query gets parsed as a dynamic query

@mosyp
Copy link
Collaborator

mosyp commented May 21, 2018

@gbogard Query is dynamic because you have specify the type of quotation, please remove that and it will be compile static, see http://getquill.io/#quotation-compile-time-quotations for more information.
However the wrong query is produced because the type of insertMeta is also explicitly set.

@gbogard To resolve your issue please remove explicit type in quote and insertMeta as in https://scastie.scala-lang.org/9CUJtp1WSi6kNWL5cUTgtA
By the way, there's no need to provide insertMeta since id column is already cut off with returning(_.id)

@mosyp
Copy link
Collaborator

mosyp commented May 21, 2018

Opened issue to add compiler error when explicit type of insertMeta is set #1105

@mosyp mosyp closed this as completed May 21, 2018
@mosyp mosyp added the question label May 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants