Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround issue #94: Using Substr with aggregate throws error #102

Open
wants to merge 1 commit into
base: azure-1.11
Choose a base branch
from

Conversation

nattster
Copy link

@nattster nattster commented Jul 4, 2017

As suggested by @shaib that Oracle backends encountered this issue as well,
they workaround by grouping parameter with same value & type. Then send modified SQL & named parameter to Database engine.

This code transform following SQL:

cursor.execute('''
SELECT 
    SUBSTRING([auth_user].[username], ?, ?) AS [first_letter], 
    COUNT_BIG([auth_user].[id]) AS [user_count] 
FROM [auth_user] 
GROUP BY SUBSTRING([auth_user].[username], ?, ?) 
ORDER BY [first_letter] ASC
''', (1, 1, 1, 1)
)

into:

cursor.execute('''
DECLARE @args0 INT = ?
SELECT 
    SUBSTRING([auth_user].[username], @args0, @args0) AS [first_letter], 
    COUNT_BIG([auth_user].[id]) AS [user_count] 
FROM [auth_user] 
GROUP BY SUBSTRING([auth_user].[username], @args0, @args0) 
ORDER BY [first_letter] ASC
''', (1, )
)

Since, pyodbc does not support Named Parameter. I have to declare variable instead.
I know that this pull request need a lot of code clean up.

It is working for me now, but would like you to help review it to improve, especially the part that map Python Data Type to SQL DataType. Suggestions/correction are greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant