从 MYSQL 迁移到 PostgreSQL
我只想将我的应用程序从 MYSQL 迁移到 PostgreSQL。我陷入了困境,
CREATE TABLE some_table
(
sequenceNumOnTarget BIGINT NOT NULL,
streamStartTime BIGINT,
intervalStartTime BIGINT NOT NULL,
intervalNumber SMALLINT,
intervalDuration INTEGER,
lastReport TINYINT,
macAddr VARCHAR(20) NOT NULL,
directoryNumber VARCHAR(30),
subnetMask VARCHAR(20),
subnetAddress VARCHAR(20),
ipAddress VARCHAR(20),
icpName VARCHAR(20),
udpPort INTEGER NOT NULL,
tcpPort INTEGER,
endpointContext SMALLINT,
endpointType SMALLINT,
farEndIpAddress VARCHAR(20),
farEndMacAddr VARCHAR(20),
farEndDirectoryNumber VARCHAR(30),
farEndUdpPort INTEGER,
farEndTcpPort INTEGER,
farEndType SMALLINT,
farEndSubnet VARCHAR(20),
farEndIcpName VARCHAR(20),
codec SMALLINT,
packetsReceived BIGINT,
DELAY INTEGER,
jitterRfc1889 INTEGER,
averageJitter INTEGER,
jitterHist0 INTEGER,
jitterHist1 INTEGER,
jitterHist2 INTEGER,
jitterHist3 INTEGER,
jitterHist4 INTEGER,
jitterHist5 INTEGER,
jitterHist6 INTEGER,
jitterHist7 INTEGER,
jitterBufferOverflow BIGINT,
jitterBufferUnderflow BIGINT,
jitterBufferAverageDepth INTEGER,
jitterBufferMaxDepth INTEGER,
packetLoss BIGINT,
packetLossMaxBurst BIGINT,
packetLossHist0 INTEGER,
packetLossHist1 INTEGER,
packetLossHist2 INTEGER,
packetLossHist3 INTEGER,
packetLossHist4 INTEGER,
packetLossHist5 INTEGER,
packetLossHist6 INTEGER,
packetLossHist7 INTEGER,
packetsOutOfOrder BIGINT,
maxJitter BIGINT,
networkMos INTEGER,
userMos INTEGER,
pollId BIGINT,
instance VARCHAR(100),
ttime BIGINT NOT NULL,
PRIMARY KEY (sequenceNumOnTarget,macAddr,udpPort),
INDEX vq_subnet(subnetAddress),
INDEX vq_ttime(ttime),
INDEX vq_pollid(pollId),
INDEX vq_sequence(sequenceNumOnTarget),
INDEX vq_icp(icpName)
);
这是我在 MySQL 中的表定义,现在我想将其转换为 PostgreSQL。
但在 PostgreSQL 中找不到适合“用一个查询创建表和索引”的 DDL 语句。
有谁可以帮忙..
I just want to migrate my application from MYSQL to PostgreSQL. I am stuck at one point,
CREATE TABLE some_table
(
sequenceNumOnTarget BIGINT NOT NULL,
streamStartTime BIGINT,
intervalStartTime BIGINT NOT NULL,
intervalNumber SMALLINT,
intervalDuration INTEGER,
lastReport TINYINT,
macAddr VARCHAR(20) NOT NULL,
directoryNumber VARCHAR(30),
subnetMask VARCHAR(20),
subnetAddress VARCHAR(20),
ipAddress VARCHAR(20),
icpName VARCHAR(20),
udpPort INTEGER NOT NULL,
tcpPort INTEGER,
endpointContext SMALLINT,
endpointType SMALLINT,
farEndIpAddress VARCHAR(20),
farEndMacAddr VARCHAR(20),
farEndDirectoryNumber VARCHAR(30),
farEndUdpPort INTEGER,
farEndTcpPort INTEGER,
farEndType SMALLINT,
farEndSubnet VARCHAR(20),
farEndIcpName VARCHAR(20),
codec SMALLINT,
packetsReceived BIGINT,
DELAY INTEGER,
jitterRfc1889 INTEGER,
averageJitter INTEGER,
jitterHist0 INTEGER,
jitterHist1 INTEGER,
jitterHist2 INTEGER,
jitterHist3 INTEGER,
jitterHist4 INTEGER,
jitterHist5 INTEGER,
jitterHist6 INTEGER,
jitterHist7 INTEGER,
jitterBufferOverflow BIGINT,
jitterBufferUnderflow BIGINT,
jitterBufferAverageDepth INTEGER,
jitterBufferMaxDepth INTEGER,
packetLoss BIGINT,
packetLossMaxBurst BIGINT,
packetLossHist0 INTEGER,
packetLossHist1 INTEGER,
packetLossHist2 INTEGER,
packetLossHist3 INTEGER,
packetLossHist4 INTEGER,
packetLossHist5 INTEGER,
packetLossHist6 INTEGER,
packetLossHist7 INTEGER,
packetsOutOfOrder BIGINT,
maxJitter BIGINT,
networkMos INTEGER,
userMos INTEGER,
pollId BIGINT,
instance VARCHAR(100),
ttime BIGINT NOT NULL,
PRIMARY KEY (sequenceNumOnTarget,macAddr,udpPort),
INDEX vq_subnet(subnetAddress),
INDEX vq_ttime(ttime),
INDEX vq_pollid(pollId),
INDEX vq_sequence(sequenceNumOnTarget),
INDEX vq_icp(icpName)
);
This is my table definition in MySQL and now I want to convert it to PostgreSQL.
But can't find a DDL statement suitable to 'create table and indexing both with one single query' in PostgreSQL.
Can anyone help..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以将表达式拆分为单独的表达式以进行创建和索引定义,则迁移应该很简单。
If you can split the expression into separate expressions for creation and index definition the migration should be straightforward.
我不相信您可以添加索引(除了那些隐式创建以强制执行 UNIQUE 和 PRIMARY KEY 约束的索引)作为 PostgreSQL 中 CREATE TABLE 语句的一部分。
然而,实际上没有必要这样做。如果您想确保在任何人可以看到(并因此使用)表之前创建索引,那么只需在单个事务中创建表和索引,并且仅在准备好使用表时提交事务。
这在 MySQL 中不起作用,因为模式更改发生在任何事务之外,即使使用通常支持它们的引擎也是如此。不过它应该可以在 PostgreSQL 中工作。
I don't believe you can add indexes (other than those created implicitly to enforce UNIQUE and PRIMARY KEY constraints) as part of a CREATE TABLE statement in PostgreSQL.
There is no real need to do so however. If you want to make sure that the indexes are created before anybody can see (and hence use) the table then just create the table and the indexes all inside a single transaction and only commit the transaction when you are ready for the table to be used.
That won't work in MySQL because schema changes happen outside any transactions, even if using an engine that normally supports them. It should work in PostgreSQL though.