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

Open
opened 3 months ago by mikoto · 2 comments
mikoto commented 3 months ago

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 3 months ago
mikoto cancelled time tracking 3 months ago
mikoto started working 3 months ago
mikoto stopped working 3 months ago
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 3 months ago
Poster

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” 作为驱动后问题依然存在
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Total Time Spent: 7s
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.