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: perform time zone name comparison case-insensitively #36847

Closed
rolandcrosby opened this issue Apr 15, 2019 · 3 comments · Fixed by #57250
Closed

sql: perform time zone name comparison case-insensitively #36847

rolandcrosby opened this issue Apr 15, 2019 · 3 comments · Fixed by #57250
Assignees
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. S-3-ux-surprise Issue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption.

Comments

@rolandcrosby
Copy link

In Postgres, the session timezone setting can always be set by name case-insensitively, but this isn't the case in CockroachDB. Here are examples using set timezone in Postgres 11:

PG 11, interactive
postgres=# select version();
                                                             version
----------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 11.2 (Debian 11.2-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
(1 row)

postgres=# set timezone=utc;
SET
postgres=# show timezone;
 TimeZone
----------
 UTC
(1 row)

postgres=# set timezone='america/new_york';
SET
postgres=# show timezone;
     TimeZone
------------------
 America/New_York
(1 row)

postgres=# set timezone='est';
SET
postgres=# show timezone;
 TimeZone
----------
 EST
(1 row)

postgres=# set timezone='eUrOPe/iSLe_Of_mAN';
SET
postgres=# show timezone;
      TimeZone
--------------------
 Europe/Isle_of_Man
(1 row)

postgres=# set timezone='PACIFIC/GALAPAGOS';
SET
postgres=# show timezone;
     TimeZone
-------------------
 Pacific/Galapagos
(1 row)

CockroachDB's behavior is not internally consistent and I'm not sure what the pattern is. When using set timezone interactively, utc and est are accepted, but america/new_york is not:

CockroachDB 19.1, interactive
root@localhost:26257/defaultdb> set timezone='utc';
SET

Time: 670.411µs

root@localhost:26257/defaultdb> show timezone;
  timezone
+----------+
  UTC
(1 row)

Time: 929.086µs

root@localhost:26257/defaultdb> set timezone='est';
SET

Time: 709.276µs

root@localhost:26257/defaultdb> show timezone;
  timezone
+----------+
  EST
(1 row)

Time: 919.475µs

root@localhost:26257/defaultdb> set timezone='america/new_york';
pq: invalid value for parameter "timezone": "'america/new_york'"
DETAIL: cannot find time zone "america/new_york": timezone data cannot be found
root@localhost:26257/defaultdb> set timezone='America/New_York';
SET

Time: 685.353µs

root@localhost:26257/defaultdb> show timezone;
      timezone
+------------------+
  America/New_York
(1 row)

Time: 960.559µs

And when pasing the timezone in the connection URL, the case-sensitive zone name appears to always be required: utc and est don't work, and neither does america/new_york:

CockroachDB 19.1, connection string
$ cockroach sql --url 'postgres://localhost:26257/defaultdb?sslmode=disable&timezone=utc' -e 'show timezone'
Error: pq: invalid value for parameter "TimeZone": "utc"
Failed running "sql"
$ cockroach sql --url 'postgres://localhost:26257/defaultdb?sslmode=disable&timezone=UTC' -e 'show timezone'
  timezone
+----------+
  UTC
(1 row)
$ cockroach sql --url 'postgres://localhost:26257/defaultdb?sslmode=disable&timezone=est' -e 'show timezone'
Error: pq: invalid value for parameter "TimeZone": "est"
Failed running "sql"
$ cockroach sql --url 'postgres://localhost:26257/defaultdb?sslmode=disable&timezone=EST' -e 'show timezone'
  timezone
+----------+
  EST
(1 row)
$ cockroach sql --url 'postgres://localhost:26257/defaultdb?sslmode=disable&timezone=america/new_york' -e 'show timezone'
Error: pq: invalid value for parameter "TimeZone": "america/new_york"
Failed running "sql"
$ cockroach sql --url 'postgres://localhost:26257/defaultdb?sslmode=disable&timezone=America/New_York' -e 'show timezone'
      timezone
+------------------+
  America/New_York
(1 row)

Directly motivated by #14988, but we've seen the same issue before (e.g. #31297). In the past we've said "timezones are case sensitive on Linux", but that's a distinction that Postgres doesn't make, so that seems like an unnecessary restriction.

@rolandcrosby rolandcrosby added A-sql-pgcompat Semantic compatibility with PostgreSQL S-3-ux-surprise Issue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption. labels Apr 15, 2019
@knz
Copy link
Contributor

knz commented Apr 16, 2019

I'd recommend continuing this discussion on #36864.

@awoods187 awoods187 added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Apr 22, 2019
@rafiss
Copy link
Collaborator

rafiss commented Nov 15, 2019

@rolandcrosby This seems to be working as desired now.

@otan
Copy link
Contributor

otan commented Oct 9, 2020

After #55377, we can patch go-tz to be case insensitive (lowercase the names in https://raw.githubusercontent.com/leighmcculloch/go-tz/master/zoneinfo.go) and finish this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. S-3-ux-surprise Issue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants