Pentaho kettle : how to execute “insert into … select from” with the sql script step?

StackOverflow https://stackoverflow.com/questions/4185532

  •  10-10-2019
  •  | 
  •  

سؤال

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 :)

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

Use the following code with cte as ( SELECT * FROM myInput ) select * into myTable from cte;

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top