scriptella

data type conflict while copying data using apache scriptella


i would like to copy data from an oracle to a postgresql database using scriptella .But i have an column tel ,that has different types in the two database , one is varchar and the other is a big int , how can i convert the implicitely here is the etl file .

<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
    <description>
        test script
    </description>
    <connection id="in" driver="oracle" url="jdbc:oracle:thin:@localhost:1521:XE"
        user="test" password="test">

    </connection>

    <connection id="out" driver="postgresql"
        url="jdbc:postgresql://localhost:5432/testMonoprix2" user="postgres"
        password="maher">
    </connection>
    <query connection-id="in">
        SELECT LIBELLE, ADRESSE,MATFISC,CONTACT,TEL FROM IPTECH.TMP_FOURNISSEUR;
        <script connection-id="out">
            UPDATE public.suppliers  SET is_enabled='TRUE', label=?LIBELLE, address=?ADRESSE, tax_registration_number=?MATFISC,contact=?CONTACT, tel=?TEL;
            </script>

    </query>
</etl>

here is the java code

and here is error i got

import java.io.File;
import scriptella.execution.EtlExecutor;
import scriptella.execution.EtlExecutorException;
public final class Test_Scriptella 
public static void main(String[] args) throws EtlExecutorException {
        try {
                    EtlExecutor.newExecutor(new File("oracle_etl.xml")).execute();
                      System.out.println("file executed");

                }catch(Exception ex)
                {
                    System.out.println(ex.getMessage());
                }
        }
    }

and here is the error i got

 Location: /etl/query[1]/script[1]
    JDBC provider exception: Unable to execute statement
    Error statement: 
    UPDATE public.suppliers SET is_enabled='TRUE', label=?, address=?, tax_registration_number=?,contact=?, tel=?. Parameters: [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, MONOPRIX LAFAYETTE, null, Neant, 891 656 ]
    Error codes: [42804, 0]
    Driver exception: org.postgresql.util.PSQLException: ERREUR: la colonne « tel » est de type bigint mais l'expression est de type character varying
     Hint: Vous devez réécrire l'expression ou lui appliquer une transformation de type.
     Position: 114

Solution

  • I haven't tried that but one option is to use cast() function to convert to an int:

    UPDATE public.suppliers  SET is_enabled='TRUE', label=?LIBELLE, address=?ADRESSE, tax_registration_number=?MATFISC,contact=?CONTACT, tel=cast(?TEL as bigint);