Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I did some such conversions between various databases using Jython and JDBC.</p> <p>All you need is Informix and PostgreSQL JDBC drivers in <code>CLASSPATH</code>.</p> <p>I have Informix table with <code>BYTE</code> column, and PostgreSQL table with <code>BYTEA</code> column:</p> <pre><code>-- Informix CREATE TABLE _blob_test ( id integer PRIMARY KEY, image BYTE ) -- PostgreSQL CREATE TABLE _blob_test ( id integer PRIMARY KEY, image BYTEA ) </code></pre> <p>Then you can use JDBC <code>getObject()/setObject()</code> methods to copy data:</p> <pre><code>#!/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 &gt; 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) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload