Closed xinyunaha closed 5 months ago
I'm encountering a table not found error when attempting to use Common Table Expressions (CTE) with GORM. Here is my example code and the error log.
example code:
var testResult map[string]interface{} model.DB.Clauses(exclause.NewWith("cte", "SELECT * FROM user")).Table("cte").Scan(&testResult)
error log:
Error 1146 (42S02): Table 'personnel.cte' doesn't exist
after executing the code above, the SQL statement displayed by GORM is:
[1.502ms] [rows:-] SELECT * FROM `cte`
troubleshooting attempts:
sry, I forgot to include the plugin, After using db.Use(extraClausePlugin.New()) , it's working now!
db.Use(extraClausePlugin.New())
I'm encountering a table not found error when attempting to use Common Table Expressions (CTE) with GORM. Here is my example code and the error log.
example code:
error log:
after executing the code above, the SQL statement displayed by GORM is:
troubleshooting attempts: