Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,180,668 members, 7,911,804 topics. Date: Monday, 05 August 2024 at 04:14 PM

Why Django Sql_server.pyodbc Passing Incorrect Code To MS SQL Server - Education - Nairaland

Nairaland Forum / Nairaland / General / Education / Why Django Sql_server.pyodbc Passing Incorrect Code To MS SQL Server (206 Views)

Convert PDF To MS Word FREE / Another 24 Incorrect English Statements We Big-headed Nigerians Speak. / MS SQL Server & Database Free Training (2) (3) (4)

(1) (Reply)

Why Django Sql_server.pyodbc Passing Incorrect Code To MS SQL Server by camillelola: 8:10am On Oct 24, 2018
Hi Guys,

I am a DBA in the process of migrating a Django application database from Postgres to MS SQL Server.

This application is using sql_server.pyodbc and Microsoft SQL Server ODBC driver for Linux/Ubuntu. Everything works except for queries that have a CASE WHEN and GROUP BY added to them.

From running traces I see that the SQL is actually passed to the SQL Server via the sp_prepexec procedure with MANY parameters. The parameters are variables and are different in the select vs group by, causing the error on SQL Server side.

This is just an example, the actual query is more complex:

select case when col1=@p1 then @p2 end as new_col1, sum(col2) from table group by case when col1=@p3 then @p4 end


In reality, @p1 and @p3 are the same values. So are @p2 and @p4. But SQL Server doesn't know that. This also fails if I run the same query on Postgres - so I assume this has to do with the sql_server.pyodbc package.

Has anyone come across this? What are my options? Am I doing something wrong with the configuration?


Thanks & Regards
Camillelola

(1) (Reply)

DSS Allegedly Detains Bauchi State Chairman Of ASUU Over Its Current Strike Acti / Auchi Poly Change Of Course Form For 2018/2019 Academic Session / Joseph Ayo Babalola University(jabu) Application Form 2018/19 Direct Entry Form/

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 7
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.