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
相关产品推荐
相关产品推荐

