Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upSyntax error for delete operation #998
Comments
This comment has been minimized.
|
We need to make this fail to compile. We don't support the PG tuple type (and even if we did, it wouldn't map to a Rust tuple). We should probably figure out a way to have all of the expression methods omitted from tuples. |
This comment has been minimized.
|
Also since you're probably looking for a workaround for what you're trying to do: use diesel::expression::grouped::Grouped;
let query = diesel::delete(subs::table.filter(Grouped((user_id, show_id)).eq_any(
users::table.inner_join((subs::table).inner_join(shows::table))
.select((user_id, show_id))
.filter(id.eq(test_user_id).and(title.eq(test_title))))
));
let target = subs::table
.filter(subs::user_id.eq(test_user_id))
.filter(exists(shows::table.filter(shows::title.eq(test_title).and(shows::id.eq(subs::show_id)))but that will fail to compile at the moment (supporting subselects which reference the outer table is something we're looking to fix) |
This comment has been minimized.
Undin
commented
Jul 5, 2017
|
Workaround works perfectly:) |
added a commit
that referenced
this issue
Jul 6, 2017
added a commit
that referenced
this issue
Jul 6, 2017
sgrif
closed this
in
#1002
Jul 6, 2017
This comment has been minimized.
|
FYI the workaround I gave you will no longer work in the next release. I'd do this instead (and this is probably just the best way to write the query regardless): let shows_with_title = shows::table
.select(shows::id)
.filter(shows::title.eq(test_title));
let target = subs::table
.filter(subs::user_id.eq(test_user_id))
.filter(subs::show_id.eq_any(shows_with_title));
let query = diesel::delete(target);The SQL will be: DELETE FROM subs
WHERE subs.user_id = $1
AND subs.show_id IN (
SELECT shows.id FROM shows WHERE shows.title = $2
)which should be significantly more efficient than what you were trying to write originally |
Undin commentedJul 5, 2017
Setup
Versions
Feature Flags
Problem Description
It seems that generated SQL for delete operation is not valid in some cases.
For query which described below in Steps to reproduce section
print_sql!macros prints next:but posgtres expects parens in WHERE clause:
What are you trying to accomplish?
I'm trying to delete object from table with nested select.
What is the expected output?
Success!in console and successful execution of delete operation.What is the actual output?
Steps to reproduce
up.sql
models.rs
schema.rs
lib.rs
main.rs
Checklist