You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Liquibase数据库迁移报错:near ')'语法错误 求助排查

问题排查:Liquibase变更集语法错误

错误根源

报错的核心原因是**CURRENT_TIMESTAMP()的括号写法不符合目标数据库(大概率为PostgreSQL)的语法规范**。

在PostgreSQL等主流数据库中,CURRENT_TIMESTAMP是内置的时间常量,无需添加括号;额外的括号会被数据库解析为无效语法,直接触发syntax error at or near ")"错误。

修复方案

将变更集中created和updated列的defaultValue值从CURRENT_TIMESTAMP()改为CURRENT_TIMESTAMP,去掉多余括号即可。

修复后的完整变更集代码:

<changeSet id="1.0.0" author="bohdan.taran">
    <createTable tableName="users">
        <column name="id" type="BIGINT" autoIncrement="true">
            <constraints primaryKey="true" nullable="false"/>
        </column>

        <column name="username" type="VARCHAR(100)">
            <constraints nullable="false" unique="true"/>
        </column>

        <column name="email" type="VARCHAR(255)">
            <constraints nullable="false" unique="true"/>
        </column>

        <column name="first_name" type="VARCHAR(100)">
            <constraints nullable="false"/>
        </column>

        <column name="last_name" type="VARCHAR(100)">
            <constraints nullable="false"/>
        </column>

        <column name="password" type="VARCHAR(255)">
            <constraints nullable="false"/>
        </column>

        <column name="created" type="TIMESTAMP" defaultValue="CURRENT_TIMESTAMP">
            <constraints nullable="false"/>
        </column>

        <column name="updated" type="TIMESTAMP" defaultValue="CURRENT_TIMESTAMP">
            <constraints nullable="false"/>
        </column>

        <column name="status" type="VARCHAR(25)" defaultValue="ACTIVE">
            <constraints nullable="false"/>
        </column>

    </createTable>
</changeSet>

补充说明

如果你的目标数据库是MySQL,CURRENT_TIMESTAMP()是合法写法,但结合报错提示的语法风格,当前场景更适配PostgreSQL类数据库,因此优先通过去掉括号解决问题。

内容的提问来源于stack exchange,提问作者Bohdan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 20:27:48