fermyon / feedback

Centralized repository for Fermyon Cloud feedback and bug reports
3 stars 1 forks source link

SQL query returns different column names local v cloud #52

Open benwis opened 4 months ago

benwis commented 4 months ago

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:

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 commented 4 months ago

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 commented 4 months ago

Good to know! I ended up matching on both COUNT options, but that's a good solution too.

On Fri, Apr 19, 2024, at 12:57 PM, itowlson wrote:

Thanks for flagging this @benwis https://github.com/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.)

— Reply to this email directly, view it on GitHub https://github.com/fermyon/feedback/issues/52#issuecomment-2067204265, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVBTCPOYFC2JKKEQRIGV23Y6FZLTAVCNFSM6AAAAABGOEQMPGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRXGIYDIMRWGU. You are receiving this because you were mentioned.Message ID: @.***>