Skip to content

[Bug]: CTAS cannot reparse TIMESTAMPADD unit syntax #28121

Closed

Description

@Ariznawlll

Summary

TIMESTAMPADD works in a regular SELECT and in a view, but fails in CREATE TABLE ... AS SELECT (CTAS). CTAS re-serializes the unit as a quoted string such as "hour"; its internal statement then fails to parse.

Environment

  • MatrixOne official main: 99ed717b769e261b842c2f17345bd65865fc1470
  • Clean local single-CN build and isolated data directory
  • Reproduced identically in 3/3 runs

Reproduction

CREATE TABLE src (id INT PRIMARY KEY, dt DATETIME(6) NOT NULL);
INSERT INTO src VALUES (1, '2024-01-01 00:00:00.123456');

SELECT TIMESTAMPADD(HOUR, 1, dt) FROM src;
-- 2024-01-01 01:00:00.123456

CREATE TABLE ctas_timestampadd AS
SELECT TIMESTAMPADD(HOUR, 1, dt) AS v FROM src;

Actual result:

ERROR 1105 (HY000): syntax error ... near '"hour", 1, `src`.`dt`) ...'

The same result occurs with a DAY unit and for TIMESTAMP input.

Scope control

The equivalent view is created and queried successfully:

CREATE VIEW v AS SELECT TIMESTAMPADD(HOUR, 1, dt) AS v FROM src;
SELECT * FROM v;
-- 2024-01-01 01:00:00.123456

DATE_ADD(..., INTERVAL 1 HOUR) CTAS is also a successful control. This isolates the failure to CTAS's serialization/reparse of TIMESTAMPADD, rather than the function evaluator or general derived-table use.

Preliminary code observation

CTAS formats the source SELECT and reparses it as an internal INSERT ... SELECT. The reserialized TIMESTAMPADD unit becomes a quoted string (for example "hour"), while the parser expects the unit token form. restoreIntervalSyntaxForCTAS restores interval(value, unit) syntax but does not cover TIMESTAMPADD(unit, value, expression). This is an observation of the failing path, not a proposed fix.

Suggested regression coverage

Add CTAS cases for TIMESTAMPADD with HOUR and DAY units, with both DATETIME(6) and TIMESTAMP(6) input; keep normal SELECT and view cases as controls.

Activity

  1. added
    kind/bug
    on Sep 4, 2026
  2. added this to the MO-202609 milestone on Sep 4, 2026
  3. added theissue type on Sep 4, 2026
  4. jiangxinmeng1 commented on Sep 14, 2026

    @jiangxinmeng1
    Contributor

    fixed by #28316

  5. Ariznawlll commented on Sep 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:be30a70fe50eac4e8c78e5117fdd69179ba853e0
    • 部署方式:本地全新单 CN mo-service,独立数据目录
    • 测试日期:2026-09-14

    原问题验证

    以含 DATETIME(6) 与 TIMESTAMP(6) 的源表执行 CREATE TABLE ... AS SELECT TIMESTAMPADD(HOUR, 1, dt), TIMESTAMPADD(DAY, 1, ts)。连续 3 次均完成 CTAS;此前被重新格式化为带引号 unit 的内部 SQL 不再报语法错误。

    Happy Path 覆盖

    1. TIMESTAMPADD(HOUR, 1, dt) 物化为 2024-03-10 07:30:00.123456。
    2. TIMESTAMPADD(DAY, 1, ts) 物化为 2024-03-11 06:30:00.123456。
    3. 两条结果均保留 123456 微秒,覆盖不同 unit 与两类时态输入。

    Unhappy Path 覆盖

    不适用:问题是合法 TIMESTAMPADD unit 在 CTAS 内部序列化后不可解析,不是用户非法 SQL。建表、物化和读取成功覆盖了原先的失败重解析点。

    白盒验证

    执行 go test -vet=off ./pkg/sql/plan -run 'TestCreateTableAsSelectUsesTemporalASTSyntax|TestCreateTableAsSelectWithTemporalFractionalSeconds' -count=1,通过。

    回归测试

    测试证据

    定向结果与预期基线见 MOTR PR #170。该 case 在 14_issue_regression 套件实跑中为 22/22 statements 通过;套件内其他既有 case 的失败未修改。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions