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: support more values for DateStyle session parameter #41773

Open
rafiss opened this issue Oct 21, 2019 · 7 comments
Open

sql: support more values for DateStyle session parameter #41773

rafiss opened this issue Oct 21, 2019 · 7 comments
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL A-tools-pgjdbc C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@rafiss
Copy link
Collaborator

rafiss commented Oct 21, 2019

full docs: https://www.postgresql.org/docs/9.5/runtime-config-client.html#GUC-DATESTYLE

Sets the display format for date and time values, as well as the rules for interpreting ambiguous date input values. For historical reasons, this variable contains two independent components: the output format specification (ISO, Postgres, SQL, or German) and the input/output specification for year/month/day ordering (DMY, MDY, or YMD). These can be set separately or together. The keywords Euro and European are synonyms for DMY; the keywords US, NonEuro, and NonEuropean are synonyms for MDY. See Section 8.5 for more information. The built-in default is ISO, MDY, but initdb will initialize the configuration file with a setting that corresponds to the behavior of the chosen lc_time locale.

Epic CRDB-2508

Jira issue: CRDB-6339

@rafiss rafiss added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-pgcompat Semantic compatibility with PostgreSQL labels Oct 21, 2019
@asubiotto asubiotto moved this from Triage to [TENT] SQL Features in [DEPRECATED] Old SQLExec board. Don't move stuff here Apr 2, 2020
@rafiss rafiss added this to Triage in SQL Sessions - Deprecated via automation Feb 17, 2021
@jjathman
Copy link

As another data point for this issue, we are attempting to use Oracle Golden Gate replication to move data from an existing Oracle DB to CockroachDB. OGG uses the Progress ODBC driver which appears to issue a SET DateStyle='iso, ymd' command when initiating a connection and isn't possible to disable. This appears to be a blocker for us that we can't work around.

@dbist
Copy link
Contributor

dbist commented Mar 9, 2021

we can't even pass datestyle as connection variable.

sh-4.4# cockroach sql --url 'postgresql://root@lb:26257?sslcert=%2Fcerts%2Fclient.root.crt&sslkey=%2Fcerts%2Fclient.root.key&sslmode=verify-full&sslrootcert=%2Fcerts%2Fca.crt&application_name=test&database=bank&datestyle=ISO, MDY'
#
# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.
#
# Server version: CockroachDB CCL v20.2.5 (x86_64-unknown-linux-gnu, built 2021/02/16 12:52:58, go1.13.14) (same version as client)
# Cluster ID: 22c50ba7-1579-4b8b-8e8e-641a98b25f6e
#
# Enter \? for a brief introduction.
#
root@lb:26257/bank> \q
sh-4.4# cockroach sql --url 'postgresql://root@lb:26257?sslcert=%2Fcerts%2Fclient.root.crt&sslkey=%2Fcerts%2Fclient.root.key&sslmode=verify-full&sslrootcert=%2Fcerts%2Fca.crt&application_name=test&database=bank&datestyle=MDY, ISO'
#
# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.
#
ERROR: setting datestyle must be absent or ISO, MDY; got MDY, ISO
Failed running "sql"

@vy-ton
Copy link
Contributor

vy-ton commented Apr 30, 2021

@rafiss Can we revisit this for the May milestone?

@rafiss
Copy link
Collaborator Author

rafiss commented Apr 30, 2021

I hope that we can get started on it, but this will have the same complexities as described in #62313 (review) -- will need a potentially big refactor/new interfaces.

@rafiss rafiss added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label May 12, 2021
@rafiss rafiss moved this from Shorter term backlog to July 2021 in SQL Sessions - Deprecated Jul 1, 2021
@otan
Copy link
Contributor

otan commented Jul 27, 2021

I started working on a library to work across all styles (ISO,Postgres,SQL,German), but it turns out we only need the order components {MDY,YMD,DMY} to work maintaining the ISO style. That's a lot simpler, I'll be doing that instead.

If anyone wants to embark on this for future work, I've started that work here https://github.com/cockroachdb/pgdatetime. I have basically attempted to copy Postgres's parse logic, I have the tokens, formatting and some parsing logic working. But there are many road bumps to go:

craig bot pushed a commit that referenced this issue Aug 2, 2021
68093: sql: allow YMD, DMY for DateStyle as a session variable r=rafiss a=otan

Refs: #41773

See individual commits for details.

68289: colexec: fix LIKE operators when patterns have escape characters r=yuzefovich a=yuzefovich

**colexec: fix LIKE operators when patterns have escape characters**

Fixes: #68040.

Release note (bug fix): Previously, CockroachDB could incorrectly
evaluate LIKE expressions when the pattern contained the escape
characters `\` if the expressions were executed via the vectorized
engine.

**colbuilder: force planning of optimized projection operators**

Whenever we're planning a projection expression, we have 3 cases: the
left is constant, the right is constants, and neither are constants. For
the second case we have some optimized operators. Previously, those
operators weren't exercised via the TestEval/vectorized because in the
eval tests the left side is constant. This commit switches the planning
to force planning of those optimized operators. This shouldn't really
have an effect on planning of actual queries.

This was prompted by the bug in LIKE operators that is fixed in the
previous commit. Had we forced the planning for our eval tests, we would
have caught it earlier.

This also revealed an incompatibility for our IN operator implementation when
the right side is an empty tuple which this commit also fixes. However,
I don't think this scenario can be hit in production because the
optimizer folds such an expression into correct `false`. Thus, there is
no release note.

Release note: None

Co-authored-by: Oliver Tan <otan@cockroachlabs.com>
Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
@otan otan removed their assignment Aug 8, 2021
@otan
Copy link
Contributor

otan commented Aug 8, 2021

Support for ISO / MDY,DMY,YMD is complete.
Other formats are not yet supported as they cannot be parsed, see previous comment.

@otan otan moved this from July 2021 to Longer term backlog in SQL Sessions - Deprecated Aug 11, 2021
@otan
Copy link
Contributor

otan commented Aug 30, 2021

heads up stuff like

VALIDUNTIL: `UPSERT INTO system.role_options (username, option, value) VALUES ($1, 'VALID UNTIL', $2::timestamptz::string)`,
needs to always needs to convert as ISO if we decide to support a non-ISO DateStyle.

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 A-tools-pgjdbc C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
No open projects
Development

No branches or pull requests

5 participants