Search code examples
etltalendanalysis

Retrieve from dynamically named tables


I'm using Talend Open Studio for Data Integration.

I have tables that are generated every day and table names are suffixed by date like so

  • dailystats20220127
  • dailystats20220126
  • dailystats20220125
  • dailystats20220124

I have two-part question. I want to look at the table which has yesterday's date in it so sysdate - 1 and I want to fetch data from yesterday

select 'dailystats' ||to_char(sysdate - 1,'YYYYMMDD') TableName  
from  dual;
  1. How do I retrieve schema for a dynamic name?
  2. How do I pull data from that table.

enter image description here

I've worked with static table names and its a straightforward process.


Solution

    1. If the schema is always the same, you just define it once in your input component.
    2. In your input component set the sql as :

    "select [fields] from dailystats"+ TalendDate.formatDate("yyyyMMdd", TalendDate.addDate(TalendDate.getCurrentDate(), -1, "dd"))