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

MySQL迁移PostgreSQL:pgloader列名自动转小写问题求助

解决pgloader迁移时保留MySQL大小写列名的问题

要实现和MySQL结构完全一致的迁移,核心是让pgloader在生成PostgreSQL表结构时保留原标识符(列名、表名)的大小写,具体可通过以下两种方式实现:

方法1:使用pgloader配置文件(推荐,更易维护)

创建一个后缀为.load的配置文件,比如mysql_migration.load,内容如下:

LOAD DATABASE
     FROM mysql://root:password@localhost/accessdatabase
     INTO postgresql://postgres:password@postgres/accessdatabase

     WITH preserve identifiers case,
          create tables,
          create indexes,
          reset sequences;

执行迁移命令:

pgloader mysql_migration.load

方法2:直接在命令行添加参数

若不想编写配置文件,可在原命令后追加--with preserve identifiers case参数:

pgloader --with preserve identifiers case mysql://root:password@localhost/accessdatabase \
 postgresql://postgres:password@postgres/accessdatabase

注意事项

PostgreSQL中,带双引号的标识符会区分大小写,因此后续查询这些列时必须用双引号包裹。比如原列名为UserName,查询时需写:

SELECT "UserName" FROM your_table;

如果不加引号,PostgreSQL会自动将标识符转为小写username,进而提示列不存在。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 23:35:17