我正在将Informix(11.7)DB迁移到PostgreSQL(9.2)。只有一个问题:如何将blob(图像)从Informix移动到PostgreSQL(9.2)?提前谢谢了。
答案 0 :(得分:1)
我使用Jython和JDBC在各种数据库之间进行了一些此类转换。
您需要的只是CLASSPATH
中的Informix和PostgreSQL JDBC驱动程序。
我的Informix表包含BYTE
列,PostgreSQL表包含BYTEA
列:
-- Informix
CREATE TABLE _blob_test (
id integer PRIMARY KEY,
image BYTE
)
-- PostgreSQL
CREATE TABLE _blob_test (
id integer PRIMARY KEY,
image BYTEA
)
然后您可以使用JDBC getObject()/setObject()
方法来复制数据:
#!/usr/bin/env jython
# -*- coding: utf8 -*-
from java.sql import DriverManager
from java.lang import Class
Class.forName("com.informix.jdbc.IfxDriver")
Class.forName('org.postgresql.Driver')
def copy_table(db_from, db_to):
col_count = 2
insert_stmt = db_to.prepareStatement('INSERT INTO _blob_test (id, image) VALUES (?, ?)')
pstm2 = db_from.createStatement()
pstm2.setFetchSize(10000)
rs_in = pstm2.executeQuery('SELECT * FROM _blob_test')
try:
batch_buffer = 0
batch_size = 100
while (rs_in.next()):
for i in range(1, col_count + 1):
insert_stmt.setObject(i, rs_in.getObject(i))
insert_stmt.addBatch()
batch_buffer += 1
if (batch_buffer % batch_size == 0):
insert_stmt.executeBatch()
batch_buffer = 0
if (batch_buffer > 0):
insert_stmt.executeBatch()
finally:
rs_in.close()
pstm2.close()
db_from = DriverManager.getConnection('jdbc:informix-sqli://informix-test:9088/infdb:informixserver=ol_testifx;DB_LOCALE=pl_PL.CP1250;CLIENT_LOCALE=pl_PL.CP1250;charSet=CP1250', 'informix', '12345')
db_to = DriverManager.getConnection('jdbc:postgresql://pg-test:5490/pg_test?stringtype=unspecified', 'postgres', '12345')
copy_table(db_from, db_to)
答案 1 :(得分:0)