I'm facing below error while using pandas to_sql for entering data into my SQL SERVER database:
ERROR:
(pymssql.ProgrammingError) (102, b"Incorrect syntax near '('.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")
Code:
connection = sqlalchemy.create_engine('mssql+pymssql://' + self.username + ":" + self.password + "@" +self.Server + "/" + self.Database, echo=False, isolation_level="AUTOCOMMIT" )
chunks = pandas.read_csv(self.input_file, chunksize=100000)
for chunk in chunks:
chunk.to_sql(table_name, if_exists='append', con=connection, index=False)
Table Structure:
CREATE TABLE [table_name] (
[index] varchar(200) NOT NULL,
[ColumnA (unit)] varchar(255),
[ColumnB] float,
CONSTRAINT PK_table_name PRIMARY KEY NONCLUSTERED ([index])
)
NOTE: I feel like the error is because of the '(' in column names. But I just can't remove it from column names in the database.
Any other answer/suggestion is welcome. Advance thanks.