Skip to content

[Bug]: CTAS rejects CAST literal AS DATETIME(6) #25524

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

Searched existing issues for:

  • CTAS datetime(6) syntax error
  • datetime(6) CTAS
  • cast datetime(6) create table as select

No exact duplicate was found.

MatrixOne version

Verified on latest main at ec01c62e4.

MySQL version

Local MySQL 8.x.

Reproduce steps

drop database if exists repro_ctas_datetime6;
create database repro_ctas_datetime6;
use repro_ctas_datetime6;

create table t as
select cast('2025-05-06 07:08:09.123456' as datetime(6)) as dt_lit;

select dt_lit from t;
select table_name,column_name,column_type,is_nullable
from information_schema.columns
where table_schema='repro_ctas_datetime6'
order by ordinal_position;

Expected behavior

Same as MySQL: CTAS succeeds and preserves datetime(6) metadata.

dt_lit
2025-05-06 07:08:09.123456

table_name  column_name  column_type  is_nullable
t           dt_lit       datetime(6)  YES

Actual behavior

MatrixOne rejects the CTAS statement with a parser error:

ERROR 1105 (HY000): You have an error in your SQL syntax; check the manual that corresponds to your MatrixOne server version for the right syntax to use. syntax error at line 1 column 109 near ", 6)) as dt_lit)";

Additional information

A broader CTAS/UNION probe also failed when datetime(6) was part of the CTAS select-list type inference. When the same literal is downgraded to cast(... as datetime) or converted to text, the rest of the CTAS/window/nested-view matrix can run.

Activity

  1. added this to the MO-202607 milestone on Jul 8, 2026
  2. added
    kind/bug
    on Jul 8, 2026
  3. added theissue type on Jul 8, 2026
  4. daviszhen commented on Jul 31, 2026

    @daviszhen
    Contributor

    fixed

  5. Ariznawlll commented on Aug 5, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:e31ee06042bc708ac5620a579715e07ec31c21b6
    • 部署方式:本地隔离单 LOG/TN/CN,MySQL text protocol
    • 测试日期:2026-08-05

    原问题验证

    原始 CTAS CAST(... AS DATETIME(6)) 连续 3/3 成功,值精确为 2025-05-06 07:08:09.123456,information_schema 元数据为 DATETIME(6) 且 nullable=YES。

    Happy Path 覆盖

    1. 单行 DATETIME(6) CTAS 的值和 FSP 元数据正确。
    2. TIME(3) 与 TIMESTAMP(6) 同一 CTAS 均保留类型精度。
    3. DATETIME(6) UNION ALL CTAS 精确保留两条微秒值。

    Unhappy Path 覆盖

    1. DATETIME(7) 返回普通 1064,bad_fsp_ctas 数量为 0。
    2. 同名目标重复 CTAS 返回 1050,原 dt_ctas 仍为 1 行且原值不变。
    3. 两类失败后 session 均可继续执行。

    白盒验证

    修复 PR #26349 已包含 temporal FSP 格式化、parser round-trip 和 CTAS planner UT;本轮验证公开 SQL 物化与元数据。

    回归测试

    MatrixOne 已有对应 BVT:create_table_as_select.sql,覆盖 DATETIME(6) 和 UNION ALL,无需重复加入 motr。

    测试证据

    三轮均得到 DATETIME(6)/TIME(3)/TIMESTAMP(6) 正确元数据、两条 UNION 值、非法 FSP 目标不存在、重复目标内容未变化。

    测试结论

    测试通过。

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