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

sql: add a hint for timestamptz -> string error #66454

Merged
merged 1 commit into from
Jun 15, 2021

Conversation

RaduBerinde
Copy link
Member

This adds a hint to the error that you get if you try to cast a
TIMESTAMPTZ to STRING in a computed column expression. It mentions a
workaround where you first convert to a timestamp using a specific
timezone.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable


case fromFamily == types.TimestampTZFamily && toFamily == types.StringFamily:
err = errors.WithHint(err, "TIMESTAMPTZ to STRING casts depend on the current timezone; "+
"consider using (t AT TIME ZONE 'UTC')::STRING instead.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add

case fromFamily == types.TimestampTZFamily && toFamily == types.TimestampFamily:

too?

@blathers-crl blathers-crl bot requested a review from otan June 14, 2021 22:08
Copy link
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @otan)


pkg/sql/sem/tree/type_check.go, line 515 at r1 (raw file):

Previously, otan (Oliver Tan) wrote…

should we add

case fromFamily == types.TimestampTZFamily && toFamily == types.TimestampFamily:

too?

Great idea. I refactored the code a bit to make this cleaner, the hint is now stored in the cast struct.

This adds hint to the error that you get if you try to cast a
TIMESTAMPTZ to TIMESTAMP or STRING in a computed column expression.

Release note: None
@RaduBerinde
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jun 15, 2021

Build succeeded:

@craig craig bot merged commit a61f01d into cockroachdb:master Jun 15, 2021
@RaduBerinde RaduBerinde deleted the timestamptz-hint branch June 15, 2021 16:47
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

Successfully merging this pull request may close these issues.

3 participants