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

TiDB returns an error when to try select INTERVAL 1 DAY + "1997-12-31" #30253

Closed
espresso98 opened this issue Nov 30, 2021 · 5 comments · Fixed by #35390
Closed

TiDB returns an error when to try select INTERVAL 1 DAY + "1997-12-31" #30253

espresso98 opened this issue Nov 30, 2021 · 5 comments · Fixed by #35390
Assignees

Comments

@espresso98
Copy link
Collaborator

Bug Report

TiDB returns an error when to try select INTERVAL 1 DAY + "1997-12-31" but, supports it in the reverse form.

1. Minimal reproduce step (Required)

select INTERVAL 1 DAY + "1997-12-31";

2. What did you expect to see?

mysql> select INTERVAL 1 DAY + "1997-12-31";
+-------------------------------+
| INTERVAL 1 DAY + "1997-12-31" |
+-------------------------------+
| 1998-01-01                    |
+-------------------------------+
1 row in set (0.01 sec)

3. What did you see instead

TiDB> select INTERVAL 1 DAY + "1997-12-31";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 17 near "1 DAY + "1997-12-31"


TiDB> select "1997-12-31" + INTERVAL 1 DAY;
+-------------------------------+
| "1997-12-31" + INTERVAL 1 DAY |
+-------------------------------+
| 1998-01-01                    |
+-------------------------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

tidb_version(): Release Version: v5.2.2
Edition: Community
Git Commit Hash: da1c21fd45a4ea5900ac16d2f4a248143f378d18
Git Branch: heads/refs/tags/v5.2.2
UTC Build Time: 2021-10-20 06:03:29
GoVersion: go1.16.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)
@espresso98 espresso98 added the type/bug The issue is confirmed as a bug. label Nov 30, 2021
@kennytm
Copy link
Contributor

kennytm commented Nov 30, 2021

adding a parser rule mapping "INTERVAL" Expression TimeUnit '+' BitExpr should be sufficient to fix this.

| BitExpr '+' "INTERVAL" Expression TimeUnit %prec '+'

@Defined2014
Copy link
Contributor

/assign

@Defined2014
Copy link
Contributor

/unassign

@Defined2014
Copy link
Contributor

Defined2014 commented Dec 2, 2021

Tried on #30312 , it will cause select INTERVAL(0,1,1,1) parse to fail.
And try to follow mysql, it will have shift/reduce problems.

@bb7133
Copy link
Member

bb7133 commented Dec 2, 2021

I don't think this is a major bug: select INTERVAL 1 DAY + "1997-12-31"; is not a common usecase and it can be workarounded easily.

@mjonss mjonss self-assigned this Jun 9, 2022
morgo added a commit to morgo/tidb that referenced this issue Jun 28, 2022
* upstream/master:
  sessionctx: support encoding and decoding session variables (pingcap#35531)
  planner: add batch_point_get access object (pingcap#35230)
  sessionctx: set skipInit false for TiDBOptProjectionPushDown and TiDBOptAggPushDown (pingcap#35491)
  *: add support for disabling noop variables (pingcap#35496)
  lightning: add store write limiter (pingcap#35193)
  expression: avoid padding 0 when implicitly cast to binary (pingcap#35053)
  types: fix creating partition tables fail in ANSI_QUOTES mode (pingcap#35379)
  executor: add the missed runtime stats when the index merge partial task returns 0 row (pingcap#35297)
  statistics: batch insert topn and bucket when saving table stats (pingcap#35326)
  parser: Add support for INTERVAL expr unit + expr (pingcap#30253) (pingcap#35390)
  config: add missing nodelay example (pingcap#35255)
  *: Introduce `OptimisticTxnContextProvider` for optimistic txn (pingcap#35131)
  statistics: fix panic when using wrong globalStats.Indices key (pingcap#35424)
  *: fix store token is up to the limit in test (pingcap#35374)
  *: enable more flaky and update bazel config (pingcap#35500)
  ddl: expose getPrimaryKey() as a public method of model.TableInfo (pingcap#35512)
  expression, util: add `KeyWithoutTrimRightSpace` for collator (pingcap#35475)
  infoschema: try on each PD member until one succeeds or all fail (pingcap#35285)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants