Migration from MYSQL to PostgreSQL
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..
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.
If you can split the expression into separate expressions for creation and index definition the migration should be straightforward.
精彩评论