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

Recursive CTEs in SQLite not working? #1841

Closed
mfreeborn opened this issue Apr 29, 2022 · 3 comments
Closed

Recursive CTEs in SQLite not working? #1841

mfreeborn opened this issue Apr 29, 2022 · 3 comments

Comments

@mfreeborn
Copy link
Contributor

rustc: 1.60.0
sqlx: 0.5.11
sqlite: 3.36.0
os: ubuntu 20.04

I've got a recursive CTE which I am calling with the query! macro that, simplified, looks like this:

WITH RECURSIVE datetimes(dt) AS (
  VALUES('2022-04-29 22:00:00')
   UNION ALL
   SELECT datetime(dt, '-1 hour')
   FROM datetimes
   WHERE dt > datetime('2022-04-29 22:00:00', '-23 hour')
)
SELECT * FROM datetimes;

I'm getting the following error:

error: attempted to communicate with a crashed background worker
   --> /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-0.5.11/src/macros.rs:315:9
    |
301 | / macro_rules! query (
302 | |     // in Rust 1.45 we can now invoke proc macros in expression position
303 | |     ($query:expr) => ({
304 | |         $crate::sqlx_macros::expand_query!(source = $query)
...   |
315 | |         $crate::sqlx_macros::expand_query!(source = $query, args = [$($args)*])
    | |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation (#2)
316 | |     })
317 | | );
    | |__- in this expansion of `sqlx::query!` (#1)
    |
   ::: /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-macros-0.5.11/src/lib.rs:28:1
    |
28  |   pub fn expand_query(input: TokenStream) -> TokenStream {
    |   ------------------------------------------------------ in this expansion of `$crate::sqlx_macros::expand_query!` (#2)
    |
   ::: backend/src/db.rs:542:22
    |
542 |       let activities = sqlx::query!(
    |  ______________________-
543 | |         r#"
544 | |             WITH RECURSIVE datetimes(dt) AS (
545 | |               VALUES('2022-04-29 22:00:00')
...   |
552 | |         "#,
553 | |     )
    | |_____- in this macro invocation (#1)

Copy and pasted directly into DB Browser for SQLite - it works just fine. Is this a limitation in Sqlx or, quite possibly, an oversight of something on my part?

@abonander
Copy link
Collaborator

@abonander
Copy link
Collaborator

Also, you could try the changes in #1816 to see if they fix your problem.

@mfreeborn
Copy link
Contributor Author

#1816 certainly gets me further. I'll keep an eye on that PR and, in the meantime, the non-macro version works well.

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

2 participants