Skip to content
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

日志中的sql和实际执行的不一致 #6533

Closed
scrawld opened this issue Aug 18, 2023 · 3 comments
Closed

日志中的sql和实际执行的不一致 #6533

scrawld opened this issue Aug 18, 2023 · 3 comments
Assignees
Labels

Comments

@scrawld
Copy link

scrawld commented Aug 18, 2023

GORM Playground Link

https://github.com/go-gorm/gorm/tree/v1.25.3

Description

表结构

CREATE TABLE `user1` (
  `uid` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL,
  `create_date` varchar(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL,
  `num` int NOT NULL DEFAULT '0',
  PRIMARY KEY (`uid`,`create_date`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin;

伪造数据
INSERT INTO `test`.`user1` (`uid`, `create_date`, `num`) VALUES ('zzz', '2023-08-18', 1);

查询

m := map[string]interface{}{}
db.Table("user1").Where("create_date=?", time.Unix(1692288000, 0)).Take(&m)
fmt.Println(m)

日志中打印出来的sql

[0.332ms] [rows:1] SELECT * FROM `user1` WHERE create_date='2023-08-18 00:00:00' LIMIT 1

实际执行的sql
SELECT * FROM `user1` WHERE create_date='2023-08-18' LIMIT 1

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Aug 18, 2023
@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@LYQlemon
Copy link

I think you can solve your problem by adding .Format("2006-04-02") after the time.Unix method

@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants