Home > OS >  GORM converts query text into lowercase
GORM converts query text into lowercase

Time:10-13

response := db.Where("createdAt BETWEEN ? AND ?", today, tomorrow).Find(&orders)

I want to make a query with GORM. The column in my table is named "createdAt" but GORM converts it to. "createdat"

    ERROR: column "createdat" does not exist (SQLSTATE 42703)
[172.521ms] [rows:0] SELECT * FROM "Orders" WHERE `createdAt` BETWEEN '2021-04-21 04:00:00' AND '2021-04-22 04:00:00'

How can I prevent GORM from converting the query text to lowercase?

CodePudding user response:

Its not gorm's issue its database issue means in database column is created with name created_at just check there and try replacing your code with this

response := db.Where("created_at BETWEEN ? AND ?", today, tomorrow).Find(&orders)

CodePudding user response:

If you use case sensitive column name, use \",ex: \"createdAt\", No modern database cannot handle upper or lower case text.

  • Related