Skip to content

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

Open
@ivothgle

Description

@ivothgle

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions