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

SQL syntax when call delete method #2911

Open
lynt1 opened this issue Oct 10, 2023 · 4 comments
Open

SQL syntax when call delete method #2911

lynt1 opened this issue Oct 10, 2023 · 4 comments

Comments

@lynt1
Copy link

lynt1 commented Oct 10, 2023

This template isn't a strict requirement to open issues, but please try to provide as much information as possible.

Version: 4.8.0
Module: quill-jdbc-zio
Database: mariadb 10.9

Steps to reproduce the behavior

Run: querySchema("Person").filter(person => person.age == 3).delete
With error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'person WHERE person.age = 3' at line 1

@getquill/maintainers

@guizmaii
Copy link
Member

guizmaii commented Oct 10, 2023

You might need to lift the 3:

def deletePersonWithId(id: Int) = 
  quote {
    querySchema[Person]("Person").filter(_.age == lift(id)).delete
  }

@lynt1
Copy link
Author

lynt1 commented Oct 11, 2023

You might need to lift the 3:

def deletePersonWithId(id: Int) = 
  quote {
    querySchema[Person]("Person").filter(_.age == lift(id)).delete
  }

@guizmaii I do same as your comment but I still get error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'x6 WHERE x6.age = 3' at line 1.

@guizmaii
Copy link
Member

@lynt1 What is the generated query, please? Because the code seems to be valid.

@ponomarevDmitri
Copy link

@lynt1 What is the generated query, please? Because the code seems to be valid.

I faced a similar problem. It seems the reason is that generated query uses an alias in a way that Mariadb "does not support".
In my case for some test table:

case class TestQuillDelete(id: Long)

and

quill.run(quote(query[TestQuillDelete].filter(_.id < lift(2L)).delete))

The generated query is:

DELETE FROM test_quill_delete x1 WHERE x1.id < ?
        quill.run(quote(query[TestQuillDelete].filter(_.id < lift(2L)).delete))

Which is executed with similar to topic starter's error.

Whereas a query without aliases executed correctly:
DELETE FROM test_quill_delete WHERE id < 2;

Versions:
quill-jdbc-zio: 4.8.3
MariaDB: 11.3.2

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

3 participants