Search code examples
sqlcommon-table-expressionazure-synapse-analytics

Can SQL scripts with shared CTE names be run in parallel?


I have two sql scripts, and they both have CTEs. The CTEs have the same name in the two scripts. For example:

Script1:
with c1 as (
  select * from t1
),
c2 as (
  select * from t2
)

Script2:
with c1 as (
  select * from t3
)

My question is, given the fact that both scripts have a CTE named c1, can I run the scripts in parallel?

Thank you :)

I have tried running the scripts in parallel, but I'm getting weird errors, so I wanna make sure it's not the share CTE names across the two scripts that's causing the problem.


Solution

  • Yes, you can run the scripts in parallel. The CTEs will be executed independently, so there is no risk of data corruption or race conditions. Though you should consider using different names for the CTEs to make your code more readable.

    Script1:
    with c1_t1 as (
      select * from t1
    ),
    c2_t2 as (
      select * from t2
    ) 
    
    Script2:
    with c1_t3 as (
      select * from t3
    )