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 query returns different column names local v cloud #52

Open
1 of 3 tasks
benwis opened this issue Apr 18, 2024 · 2 comments
Open
1 of 3 tasks

SQL query returns different column names local v cloud #52

benwis opened this issue Apr 18, 2024 · 2 comments

Comments

@benwis
Copy link

benwis commented Apr 18, 2024

Describe the bug
I want to run this query to get a count of the number of posts in the blog

        let rowset = con.execute("SELECT COUNT(*) FROM posts;", &[]).map_err(|e| {
                    println!("SQL ERROR: {e}");
                    BenwisAppError::NotFound
        })?;
        let count = rowset.rows().nth(0).map(|row| {
            row.get::<i64>("COUNT(*)").unwrap().to_owned()
       }).unwrap_or(0);

This runs fine locally, but on the server it panicked. Some debugging ensued, and I discovered that the column name returned from the local version is COUNT(*) and the cloud version is COUNT (*). That extra space is what threw me for a loop.

Frequency of the bug
Please check one:

  • Consistent repro
  • Intermittent repro
  • No repro

Set-up information
Please share the version of Spin used when the bug occurred. You can find the version of Spin by running spin -V.
Spin 2.4.2

@itowlson
Copy link

Thanks for flagging this @benwis! Per the linked issue, this is now fixed in Turso/libsql, but will take a little while to roll out to their production environment. In the meantime the proposed workaround is to do a SELECT COUNT(*) AS <something> to force the column name to be predictable. (I think you already have your own workaround, but I wanted to capture this in case other folks ran into it.)

@benwis
Copy link
Author

benwis commented Apr 19, 2024 via email

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