connector-x icon indicating copy to clipboard operation
connector-x copied to clipboard

Support for duplicate columns in MS SQL

Open bloukanov opened this issue 4 years ago • 4 comments

Hi again,

Would it be possible to allow downloading tables with multiple columns with the same name? pd.read_sql can do this

I get: RuntimeError: Token error: 'The column 'x' was specified multiple times for 'CXTMPTAB_COUNT'.' on server y executing on line 1 (code: 8156, state: 1, class: 16)

bloukanov avatar Oct 22 '21 19:10 bloukanov

Hi @bloukanov, it seems like you want two columns with the same name which I'm not sure why there is a need for this. Can you specify your use case? Also, can workarounds like using alias to rename the column solve the problem?

wangxiaoying avatar Oct 24 '21 03:10 wangxiaoying

Hi @wangxiaoying,

My use case is I have a SQL join upstream (before the download to Python), and I do not want to specify column names in it, so it is:

select a.*, b.* 
from a left join b on a.x = b.x and a.y = b.y

This way I will not have to touch this join even after adding or removing columns upstream, from tables a or b. But this causes x and y to be duplicated in the resulting dataset. For now I can work around, but I suppose this would be an issue with any "select all" join?

bloukanov avatar Oct 25 '21 14:10 bloukanov

@bloukanov I see. It might be a little bit tricky to support this in our case. Unlike pandas which directly issue the query, we need to count the query result and partition the query in advance. And in order to make sure the generated queries are valid in all cases, nested query is the safest choice, and this error is caused by the duplicated name in the subquery. We will take a look at whether there is other workarounds that we can do in our side, but it won't be in very high priority since right now it can work with specifying a different name in the SQL query. Thanks for the report anyway.

wangxiaoying avatar Oct 27 '21 17:10 wangxiaoying

@wangxiaoying got it, makes sense! thanks

bloukanov avatar Oct 27 '21 22:10 bloukanov