• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » using context variables in global sql queries

#1 2012-06-08 12:02:29

Marco Westermann
Guest

using context variables in global sql queries

Hi,

I have a set of sql-queries defined globally in my project. Many of them have an in clause like the following to filter the result set:

and p_nid in (5,6,8,9,11,13,14,15,66)

I would like to define the ids as context variable and refer them in my sql-query. Is that somehow possible?

thank you for suggestions,

regards,

Marco

#2 2012-06-08 12:06:55

pedro
Member
Registered: 2011-11-17
Posts: 3682

Re: using context variables in global sql queries

Hi Marco

The query is like this.
"and p_nid in ("+context.id1+","+"context.id2+","+context.id3+")"

Regards,
Pedro


Only Paranoid Survive.

Offline

#3 2012-06-08 15:37:19

Marco Westermann
Guest

Re: using context variables in global sql queries

Hi,

thank you very much, works like a charm.

regards, Marco

#4 2012-06-08 18:54:12

jpetsche
Member
Registered: 2012-03-19
Posts: 10

Re: using context variables in global sql queries

Could I do a similar thing where I use a context variable inside a context variable?

For example if I store just the where clause in a context variable:
context.where_sql = "in ("+context.id1+","+context.id2+","+context.id3+")"

Offline

#5 2012-06-11 03:43:53

pedro
Member
Registered: 2011-11-17
Posts: 3682

Re: using context variables in global sql queries

Hi

Sorry. Talend can't support saving context variable into context variable.

Regards,
Pedro


Only Paranoid Survive.

Offline

#6 2012-06-11 06:08:07

pgmuthukumar
Member
Registered: 2012-05-08
Posts: 79

Re: using context variables in global sql queries

can the context hold list of values?
so that way we need not to hard code/restrict the number of variables like id1, id2, ... idn

Offline

#7 2012-06-11 07:02:42

pedro
Member
Registered: 2011-11-17
Posts: 3682

Re: using context variables in global sql queries

Hi

The answer is no.

Regards,
Pedro


Only Paranoid Survive.

Offline

#8 2012-06-11 07:09:05

pgmuthukumar
Member
Registered: 2012-05-08
Posts: 79

Re: using context variables in global sql queries

ok, in that case is there any alternate way to implement?

Offline

#9 2012-06-11 17:33:46

jpetsche
Member
Registered: 2012-03-19
Posts: 10

Re: using context variables in global sql queries

The only way I know is via a tFlieDelimited. The file would contain a list of variables to use:

id1
id2
id3
...

Talend would iterate through that list. Perhaps you can call those variables another way??

Offline

#10 2012-06-11 21:57:56

avdbrink
Member
Company: Conspect Consulting & ICT
Registered: 2010-11-08
Posts: 360
Website

Re: using context variables in global sql queries

Hi,

Why not use a context variable named "ids" like this:

context.ids = "5,6,8,9";

And then in your query use:

"where id in (" + context.ids + ")"

I see no reason this could not work. Can you explain why you said no Pedro?

Regards,
Arno

Offline

#11 2012-06-12 03:38:17

pedro
Member
Registered: 2011-11-17
Posts: 3682

Re: using context variables in global sql queries

Hi Arno

I said no because I think what pgmuthukumar means is Array or List data pattern which is able to add element and remove element, not String.

Regards,
Pedro


Only Paranoid Survive.

Offline

#12 2012-06-12 07:38:18

avdbrink
Member
Company: Conspect Consulting & ICT
Registered: 2010-11-08
Posts: 360
Website

Re: using context variables in global sql queries

Hi Pedro,

Okay, I get that, that's a No indeed smile

Regards,
Arno

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » using context variables in global sql queries

Board footer

Powered by FluxBB