How to use context parameter in sql?

0

I have defined one context parameter: search_id.

Now there is one component tMySqlInput in my job.

I need to search some data by below sql:

"SELECT count(1) FROM business WHERE business_id=?"
 
In the "where clause" need to use context: search_id.
 
Can you help to give me any solutions? Thanks a lot.
fengjianquan_1's picture
Joined: Oct 8 2015 - 7:18pm
Last seen: 4 years 3 weeks ago

1 Answer:

1

Hi Ted,

unfortunately using bind variables is only allowed in row components and not input components: https://jira.talendforge.org/browse/TDI-6749

You can still concatenate the context variable to the query string as you would do in Java, for example:

"SELECT count(1) FROM business WHERE business_id = " + context.search_id

I'm assuming search_id is a number so no need to surround it with single quotes. Otherwise it would be:

"SELECT count(1) FROM business WHERE business_id = '" + context.search_id + "'"

See this screenshot for an example:

Screenshot of Talend showing tPostgresqlInput component with query using the context variable.

Please accept and/or up-vote the answer if you think it's useful, thanks!

Cheers

kkumlien's picture
2886
Joined: Jan 22 2015 - 4:36am
Last seen: 3 hours 10 min ago
Feedback
randomness