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

Why does the parsing of oid.Timestamp type not use the current session time zone? #1174

Open
ivothgle opened this issue Oct 11, 2024 · 0 comments

Comments

@ivothgle
Copy link

There is such a database table

CREATE TABLE "test"
(
  "id"               SERIAL8       NOT NULL,
  "created_at"           timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updated_at"           timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY ("id")
)

and go structure

type Test struct {
	Id        int
	CreatedAt time.Time
	UpdatedAt time.Time
}

Then, the time zone of the database configuration is PRC , and the local time zone of the go program is PRC

https://github.com/lib/pq/blob/master/encode.go#L109

The string(s) value at this time is 2024-10-11 10:00:00. Because the parseTs parameter does not contain a time zone, the time zone of the parsed time.Time is UTC, but the time zone of this date should be the database time zone PRC.

This will cause all calculations about this time to be wrong.
How should I solve this problem?

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

No branches or pull requests

1 participant