Pentaho kettle : how to execute "insert into ... select from" with the sql script step?

17,089

Solution 1

When you first edit the SQL Script step, click 'Get fields' button. This is going to load the parameters(fields from your csv) into box on the bottom left corner. Delete the parameters(fields) you don't want to insert.

In your sql script write your query something like this where the question marks are your parameters in order.

insert into my_table (field1,field2,field3...) values ('?','?','?'...);

Mark the checkboxes execute for each row and execute as a single statement. That's really about it. Let me know if you have any more questions and if you provide sample data I'll make you a sample ktr file to look at.

Solution 2

I think you get the wrong way. You should get a cvs file input step and a table output step.

As rwilliams said, In cvs file input step Get fields; the more important, in table output there is a Database Fields tab. Enter field mapping is right choise.The guess function is amazing.

And more, system can generate target table create sql statement when target table not exists in target connection Db server.

Share:
17,089
Maxime ARNSTAMM
Author by

Maxime ARNSTAMM

About Me

Updated on June 14, 2022

Comments

  • Maxime ARNSTAMM
    Maxime ARNSTAMM almost 2 years

    I am discovering Pentaho DI and i am stuck with this problem :

    I want to insert data from a csv file to a custom DB, which does not support the "insert table" step. So i would like to use the sql script step, with one request :

    INSERT INTO myTable 
    SELECT * FROM myInput
    

    And my transformation would like this :

    transformation

    I don't know how to get all my data from the csv to be injected in the "myInput" field.

    Could someone help me ?

    Thanks a lot :)