issue: 从postgresql查询timestamp类型数据,指针time和非指针time数据异常 #1848

Open
opened 2021-01-04 03:15:56 +00:00 by mikoto · 3 comments

code:

package main

import (
	"fmt"
	_ "github.com/jackc/pgx/v4/stdlib"
	_ "github.com/lib/pq"
	"time"
	"xorm.io/xorm"
)

type MyPointerTime struct {
	ID         int       `xorm:"id" json:"id"`
	CreateTime *time.Time `xorm:"create_time" json:"create_time"`
}

type MyTime struct {
	ID         int       `xorm:"id" json:"id"`
	CreateTime time.Time `xorm:"create_time" json:"create_time"`
}

func main()  {
	dbUrl := "user=postgres password=111111 host=127.0.0.1 port=5432 dbname=postgres search_path=test sslmode=disable"
	engine, err := xorm.NewEngine("pgx", dbUrl)
	if err !=nil {
		fmt.Println(err.Error())
		return
	}
	var pt [] MyPointerTime
	var t [] MyTime
	err = engine.SQL("SELECT * FROM point_time").Find(&pt)
	err = engine.SQL("SELECT * FROM point_time").Find(&t)
	if err !=nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println("Xorm Pointer Time Result: ",pt[0],pt[0].CreateTime.Unix())
	fmt.Println("Xorm Time Result:         ",t[0],t[0].CreateTime.Unix())
}

OutPut:

Xorm Pointer Time Result:  {3 2021-01-04 10:54:58.849671 +0800 CST} 1609728898
Xorm Time Result:          {3 2021-01-04 02:54:58.849671 +0800 CST} 1609700098
### code: ```go package main import ( "fmt" _ "github.com/jackc/pgx/v4/stdlib" _ "github.com/lib/pq" "time" "xorm.io/xorm" ) type MyPointerTime struct { ID int `xorm:"id" json:"id"` CreateTime *time.Time `xorm:"create_time" json:"create_time"` } type MyTime struct { ID int `xorm:"id" json:"id"` CreateTime time.Time `xorm:"create_time" json:"create_time"` } func main() { dbUrl := "user=postgres password=111111 host=127.0.0.1 port=5432 dbname=postgres search_path=test sslmode=disable" engine, err := xorm.NewEngine("pgx", dbUrl) if err !=nil { fmt.Println(err.Error()) return } var pt [] MyPointerTime var t [] MyTime err = engine.SQL("SELECT * FROM point_time").Find(&pt) err = engine.SQL("SELECT * FROM point_time").Find(&t) if err !=nil { fmt.Println(err.Error()) return } fmt.Println("Xorm Pointer Time Result: ",pt[0],pt[0].CreateTime.Unix()) fmt.Println("Xorm Time Result: ",t[0],t[0].CreateTime.Unix()) } ``` ### OutPut: ``` Xorm Pointer Time Result: {3 2021-01-04 10:54:58.849671 +0800 CST} 1609728898 Xorm Time Result: {3 2021-01-04 02:54:58.849671 +0800 CST} 1609700098 ```
mikoto started working 2021-01-04 03:19:13 +00:00
mikoto canceled time tracking 2021-01-04 03:20:21 +00:00
mikoto started working 2021-01-04 03:22:39 +00:00
mikoto stopped working 2021-01-04 03:22:46 +00:00
7s
Owner

Yes, pgx driver has some problems with time. This is a known issue.

Yes, pgx driver has some problems with time. This is a known issue.
lunny added the
kind
bug
label 2021-01-04 06:38:37 +00:00
Author

Yes, pgx driver has some problems with time. This is a known issue.

我尝试使用 “github.com/lib/pq” 作为驱动后问题依然存在

> Yes, pgx driver has some problems with time. This is a known issue. 我尝试使用 “github.com/lib/pq” 作为驱动后问题依然存在
Owner

You should use time.Time but not *time.Time. I think I will not support pointer to time.Time because it needs reflect.

You should use `time.Time` but not `*time.Time`. I think I will not support pointer to `time.Time` because it needs reflect.
lunny added
wontfix
and removed
kind
bug
labels 2021-06-06 13:01:41 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1848
No description provided.