Mat Moon
Mat Moon

Reputation: 33

FreeTDS ODBC error "The identifier that starts with ... is too long. Maximum length is 128."

I've been using pyodbc and free TDS to a submit queries to a microsoft SQL-2012 without issue for a while now but have recently stumbled on an issue. When I submit a longer query I get an error message saying that one of the identifiers is too long and the script crashes. The EXACT same query works in management studio and doesn't even return a warning. I've added the following to my code with no avail.

SET QUOTED_IDENTIFIER OFF
SET ANSI_NULLS ON

The piece of code that the error is referring to is here:

(ZR_KOPF.ZRK_DDP_B IN ('190/TEMP.AA1H', '190/RAIN.AA1H', '190/WDR.AA1H', '190/WSP.AA1H', '190/SD1.AA1H', '190/HUMID.AA1H', '190/NO2.AA1H', '190/PM10.AA1H', '190/PM2.5.AA1H', '190/SO2.AA1H', '190/OZONE.AA1H', '190/CO.AA1H', '206/TEMP.AA1H', '206/RAIN.AA1H', '206/WDR.AA1H', '206/WSP.AA1H', '206/SD1.AA1H', '206/HUMID.AA1H', '206/NO2.AA1H', '206/PM10.AA1H', '206/PM2.5.AA1H', '206/SO2.AA1H', '206/OZONE.AA1H', '206/CO.AA1H')) AND ZR_KOPF.ZRK_BASEPRODUCTION = 1)

The error I get is:

pyodbc.ProgrammingError: ('42000', "[42000] [FreeTDS][SQL Server]The identifier that starts with ''190/TEMP.AA1H', '190/RAIN.AA1H', '190/WDR.AA1H', '190/WSP.AA1H', '190/SD1.AA1H', '190/HUMID.AA1H', '190/NO2.AA1H', '190/PM10.AA' is too long. Maximum length is 128. (103) (SQLExecDirectW)")

Pyodbc version: 4.0.18b1 freetds version: 1.00.48

Any help would be much appreciated Cheers!

Upvotes: 1

Views: 798

Answers (1)

Mat Moon
Mat Moon

Reputation: 33

So turns out the spaces between each of the items in the list made all the difference... I removed them and the query worked without a hitch. Thanks for all the help everyone!

Upvotes: 0

Related Questions