0
SELECT
    $model_master_id$,
    $model_market_segment$,
    $country$,
    $ctry_cd$,
    $score_run_id$,
    $period_id$,
    $prediction_from_dt$,
    $prediction_to_dt$,
    $buy_acq$,
    $eval_prd$,
    $scr.model_score$,
    $scr.model_score_bin$
    from 
    (select 
    model_master_id,
    model_version_id,
    score_run_id,
    $site_rsdnc_id$,
    segment_name,
    model_score,
    model_score_bin
    FROM $master_scoring_table_name$) scr
    LEFT JOIN
    (SELECT
    $site_rsdnc_id$,
    $segment_column_name$ 
    FROM $feature_table_name$) f 
    ON f.$site_rsdnc_id$=scr.$site_rsdnc_id$;

Could there be a possibly simple way to achieve the above code from my attached excel Config other than dynamic sql? Everything within dollar quotes comes from my config. I tried dynamic sql with for loops but since I have multiple tablenames coming from my config the dynamic sql runs for a very long time.

enter image description here

1 Answers1

0

The simple answer is no. Literals cannot be replaced by any variable or token.

The long answer is that you already excluded the only known good answer to the question, which is to dynamically create the SQL somewhere else and feed it to PostgreSQL as a literal.

Kirk Roybal
  • 17,273
  • 1
  • 29
  • 38
  • Alright thanks. Only challenge is the query run time for what I want to achieve. So, was wondering if there could be a simpler way that I couldn't think of. – Reshmi Nair Feb 03 '22 at 21:20
  • Also, could you create a simple dynamic sql as a solution? Would want to see if there could be something that I could optimize – Reshmi Nair Feb 03 '22 at 21:26
  • No. "Can you code this for me?" is clearly against the guidelines. – Kirk Roybal Feb 05 '22 at 19:28
  • Oh I didn't know that. Sorry for my ignorance. I had raised a separate case long back for help around optimization scope, if any, for my code built. Of course, that was difficult to comprehend because of the complexities in the code around me having to stitch data from ~500 different table using psql. – Reshmi Nair Feb 07 '22 at 16:49
  • No harm, no foul. Also didn't mean to be rude. But unfortunately can't do that. – Kirk Roybal Feb 07 '22 at 18:07
  • No, that's absolutely fine. Thanks for educating me around the guidelines! Will remember that next time I raise a case. – Reshmi Nair Feb 07 '22 at 18:44