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
Error "no such table" when creating temp tables #1176
Comments
As discussed in #933, there is currently a bug in this library where passing multiple statements to Also, as a reminder, you should always check c, err := db.Conn(ctx)
if err != nil {
fmt.Printf("error: %v\n", err)
return
}
defer c.Close()
if _, err := c.ExecContext(ctx, "DROP TABLE IF EXISTS temp.deleted_watchtimes"); err != nil {
fmt.Printf("error: %v\n", err)
return
}
if _, err := c.ExecContext(ctx, "CREATE TEMP TABLE deleted_watchtimes (row_id INTEGER)"); err != nil {
fmt.Printf("error: %v\n", err)
return
}
defer c.ExecContext(ctx, "DROP TABLE temp.deleted_watchtimes")
if _, err := c.ExecContext(ctx, `
WITH cte AS (SELECT value FROM JSON_EACH(:names))
INSERT
INTO temp.deleted_watchtimes
SELECT *
FROM cte`,
sql.Named("names", `["a","b"]`),
); err != nil {
fmt.Printf("error: %v\n", err)
return
}
rows, err := c.QueryContext(ctx, "SELECT * FROM temp.deleted_watchtimes")
if err != nil {
fmt.Printf("error: %v\n", err)
return
}
defer rows.Close()
for rows.Next() {
var res string
err := rows.Scan(&res)
if err != nil {
fmt.Printf("error: %v\n", err)
return
}
fmt.Println(res)
}
if err := rows.Err(); err != nil {
fmt.Printf("error: %v\n", err)
return
} |
Thank you for the good response. Sadly I'm currently using https://github.com/qustavo/dotsql in place of stored procedures since I don't want sql statements scattered throughout my code. I'll keep an eye on this issue so I know when it's resolves so I can add it back in because I would rather use this package than the other, since I feel this one is faster and more stable. Also what is the reason for the |
|
When I create a temp table, it throws an error that the table doesn't exist. When running the commands in datagrip and the sqlite cli with parameters replaced, it does not error. As long as I don't use the temp table (joins or selects) then it doesn't error in the go code. I believe this is an issue with
go-sqlite3
or some configuration that I can't figure out because when I test it withgithub.com/glebarez/sqlite
the query executes with no errors.Actual application query
Testing sql query
Test code that errors
If I use the sql query below, it doesn't error
The text was updated successfully, but these errors were encountered: