WinterYukky / gorm-extra-clause-plugin

The clause support plugin for gorm, that not supported by gorm.
MIT License
50 stars 9 forks source link

Table 'xxx' doesn't exist when using CTE #79

Closed xinyunaha closed 5 months ago

xinyunaha commented 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:

xinyunaha commented 5 months ago

sry, I forgot to include the plugin, After using db.Use(extraClausePlugin.New()) , it's working now!