【MySQL建表语句转PostgreSQL建表语句】MySQL建表语句转PostgreSQL建表语句
生活随笔
收集整理的這篇文章主要介紹了
【MySQL建表语句转PostgreSQL建表语句】MySQL建表语句转PostgreSQL建表语句
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.首先加一下依賴
<dependency> <groupId>com.github.jsqlparser</groupId> <artifactId>jsqlparser</artifactId> <version>1.2</version> </dependency>
2.加下腳本
/**
-
@author Ben.Zhou
-
@version 1.0
-
@description
-
@data 2022/3/10 16:51
System.out.println(dDLs);dDLs = dDLs.replaceAll("current_timestamp\\(\\) ON UPDATE current_timestamp\\(\\)", "current_timestamp").replaceAll("current_timestamp\\(\\)", "current_timestamp").replaceAll("current_timestamp\\(\\)", "current_timestamp").replaceAll("int\\([0-9]*\\)", "INT").replaceAll("tinyint\\([0-9]*\\)", "INT").replaceAll("tinyINT","INT").replaceAll("double\\([0-9]*,[0-9]*\\)","float8").replaceAll("DEFAULT 00000000000","DEFAULT 0").replaceAll("unsigned zerofill","").replaceAll("bigint\\([0-9]*\\) NOT NULL AUTO_INCREMENT", "BIGSERIAL PRIMARY KEY").replaceAll("bigint\\([0-9]*\\)","INT8");//dDLs = dDLs.replaceAll("bigint\\(19\\)","int8");System.out.println("++++++++++開始轉(zhuǎn)換SQL語句+++++++++++++");Statements statements = CCJSqlParserUtil.parseStatements(dDLs);statements.getStatements().stream().map(statement -> (CreateTable) statement).forEach(ct -> {Table table = ct.getTable();List<ColumnDefinition> columnDefinitions = ct.getColumnDefinitions();List<String> comments = new ArrayList<>();List<ColumnDefinition> collect = columnDefinitions.stream().peek(columnDefinition -> {List<String> columnSpecStrings = columnDefinition.getColumnSpecStrings();int commentIndex = getCommentIndex(columnSpecStrings);if (commentIndex != -1) {int commentStringIndex = commentIndex + 1;String commentString = columnSpecStrings.get(commentStringIndex);String commentSql = genCommentSql(table.toString(), columnDefinition.getColumnName(), commentString);comments.add(commentSql);columnSpecStrings.remove(commentStringIndex);columnSpecStrings.remove(commentIndex);}columnDefinition.setColumnSpecStrings(columnSpecStrings);}).collect(Collectors.toList());ct.setColumnDefinitions(collect);
*/
public class MysqlDdl2PgDdlUtil {
public static void main(String[] args) throws IOException, JSQLParserException {
// 你的MySQL DDL路徑
String mysqlDDLPath = “C:\Users\wb_xg20\Desktop\finance_super1.sql”;
String dDLs = FileUtils.readFileToString(new File(mysqlDDLPath));
總結(jié)
以上是生活随笔為你收集整理的【MySQL建表语句转PostgreSQL建表语句】MySQL建表语句转PostgreSQL建表语句的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php cpu缓存 执行 代码,缓存PH
- 下一篇: 实现点击按钮后,倒计时60秒才能再次点击