-
Notifications
You must be signed in to change notification settings - Fork 818
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
Add ScanLocation to Timestamp and Timestamptz #1948
Conversation
If ScanLocation is set, it will be used to convert the time to the given location when scanning from the database. The Codec interface is now implemented by *pgtype.TimestamptzCodec instead of pgtype.TimestamptzCodec. This is technically a breaking change, but it is extremely unlikely that anyone is depending on this, and if there is downstream breakage it is trivial to fix. #1195 #1945
If ScanLocation is set, the timestamps will be assumed to be in the given location when scanning from the database. The Codec interface is now implemented by *pgtype.TimestampCodec instead of pgtype.TimestampCodec. This is technically a breaking change, but it is extremely unlikely that anyone is depending on this, and if there is downstream breakage it is trivial to fix. #1195 #1945
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jackc, I saw you requested feedback on #1195 (comment). Though I'm not experienced with pgx's internals, FWIW this change did address the issues we were facing in our application.
|
||
func (TimestampCodec) FormatSupported(format int16) bool { | ||
func (*TimestampCodec) FormatSupported(format int16) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Is it strictly necessary for the new codec implementations to use a pointer receiver? In both cases the only member is the *time.Location
field which is itself a pointer. As you mentioned in your commit descriptions, this is technically a breaking change, albeit a very minor one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it strictly necessary? No. But as I understand it, it is usually better for interfaces implemented by structs to use methods that receive the pointer rather than the value.
Hi! Is there a way to use the ScanLocation with pgx/v4? |
@fantapop Only if someone were to backport it. |
This setting allows configuring the
time.Location
oftime.Time
values scanned from PostgreSQLtimestamp
andtimestamptz
.For
timestamptz
it changes the display location but the instant in time is unchanged. That is, regardless of the value ofScanLocation
, the results oftime.Time.Equal()
will be the same.For
timestamp
it changes the location the time is assumed to have been in. That is, changing the value ofScanLocation
will change the results oftime.Time.Equal()
.