I'm running into an issue in production where previous Select.order\_by() statements were working. The code used to look like this: from sqlalchemy.sql import select
```
s = select([table], order\_by=[])
s = s.order\_by(params["order\_by"])
```
I suspect it has to do with the fact that the code changed to use the `text()` as follows:
```
s = select([table], order\_by=[])
s = s.order\_by(text(params["order\_by"]))
```

I am getting errors like: (psycopg2.errors.SyntaxError) syntax error at or near "ID" LINE 2: ...ROM public.hubspot\_contract\_prices ORDER BY Company ID DESC ^ [SQL: SELECT public.hubspot\_contract\_prices.celebrity\_id, public.hubspot\_contract\_prices.username, public.hubspot\_contract\_prices."Company ID", public.hubspot\_contract\_prices.precio\_personal, public.hubspot\_contract\_prices.discount\_percentage, public.hubspot\_contract\_prices.contract\_type\_id, public.hubspot\_contract\_prices.precio\_comercial, public.hubspot\_contract\_prices.descuento\_comercial, public.hubspot\_contract\_prices.contract\_comercial\_type\_id, public.hubspot\_contract\_prices.link\_al\_admin, public.hubspot\_contract\_prices.link\_al\_site FROM public.hubspot\_contract\_prices ORDER BY Company ID DESC LIMIT %(param\_1)s] [parameters: {'param\_1': 50}] (Background on this error at: https://sqlalche.me/e/14/f405)

Here is another from MySQL: (pymysql.err.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ID DESC \n LIMIT 50' at line 2") [SQL: SELECT vw\_zap\_accredible\_pearson\_pro9.`Event ID`, vw\_zap\_accredible\_pearson\_pro9.`Zoho ID`, vw\_zap\_accredible\_pearson\_pro9.`Partner Name`, vw\_zap\_accredible\_pearson\_pro9.`Partner Code`, vw\_zap\_accredible\_pearson\_pro9.`Student Type`, vw\_zap\_accredible\_pearson\_pro9.`Name to appear on Certificate`, vw\_zap\_accredible\_pearson\_pro9.`Certificate Group ID`, vw\_zap\_accredible\_pearson\_pro9.`Certification Number`, vw\_zap\_accredible\_pearson\_pro9.`Exam Series`, vw\_zap\_accredible\_pearson\_pro9.`Course Name`, vw\_zap\_accredible\_pearson\_pro9.`Email`, vw\_zap\_accredible\_pearson\_pro9.`First name`, vw\_zap\_accredible\_pearson\_pro9.`Last name`, vw\_zap\_accredible\_pearson\_pro9.`Modified Time`, vw\_zap\_accredible\_pearson\_pro9.`Course Version`, vw\_zap\_accredible\_pearson\_pro9.`Exam Date`, vw\_zap\_accredible\_pearson\_pro9.`Pearson ID`, vw\_zap\_accredible\_pearson\_pro9.`Grade`, vw\_zap\_accredible\_pearson\_pro9.`Total Exam Score`, vw\_zap\_accredible\_pearson\_pro9.`Result Exam A`, vw\_zap\_accredible\_pearson\_pro9.`Result Exam B`, vw\_zap\_accredible\_pearson\_pro9.`Result Exam C`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 1`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 2`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 3`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 4`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 5`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 6`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 7`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 8`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 9`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 10` FROM vw\_zap\_accredible\_pearson\_pro9 ORDER BY Event ID DESC LIMIT %(param\_1)s] [parameters: {'param\_1': 50}] (Background on this error at: https://sqlalche.me/e/14/f405)

And another for SQL Server: Exception occurred during get\_rows: (pyodbc.ProgrammingError) ('42000', "[42000] [FreeTDS][SQL Server]Incorrect syntax near 'Addresss'. (102) (SQLExecDirectW)") [SQL: SELECT TOP 50 dbo.[Zapier\_UK\_Mailchimp].[Email Addresss], dbo.[Zapier\_UK\_Mailchimp].[First Name], dbo.[Zapier\_UK\_Mailchimp].[Surname], dbo.[Zapier\_UK\_Mailchimp].[Brand], dbo.[Zapier\_UK\_Mailchimp].[Division], dbo.[Zapier\_UK\_Mailchimp].[Project], dbo.[Zapier\_UK\_Mailchimp].[Location], dbo.[Zapier\_UK\_Mailchimp].[Tags] FROM dbo.[Zapier\_UK\_Mailchimp] ORDER BY Email Addresss DESC] (Background on this error at: https://sqlalche.me/e/14/f405)

Notice that they all are selects using ORDER BY.
프로덕션 환경에서 이전 Select.order\_by() 문이 작동하는 문제가 발생하고 있습니다. 이전에는 다음과 같은 코드가 사용되었습니다. sqlalchemy.sql에서 select 가져오기```s = select([table], order\_by=[])s = s.order\_by(params["order\_by"])```코드가 다음과 같이 `text()`를 사용하도록 변경되었다는 사실과 관련이 있다고 생각합니다:```s = select([table], order\_by=[])s = s.order\_by(text(params["order\_by"]))```다음과 같은 오류가 발생합니다: (psycopg2.errors.SyntaxError) "ID" 2줄 또는 그 근처에서 구문 오류 발생: ...ROM public.hubspot\_contract\_prices ORDER BY Company ID DESC ^ [SQL: SELECT public.hubspot\_contract\_prices.celebrity\_id, public.hubspot\_contract\_prices.username, public.hubspot\_contract\_prices."회사 ID", public.hubspot\_contract\_prices."회사 ID". precio\_personal, public.hubspot\_contract\_prices.discount\_percentage, public.hubspot\_contract\_prices.contract\_type\_id, public.hubspot\_contract\_prices. precio\_comercial, public.hubspot\_contract\_prices.descuento\_comercial, public.hubspot\_contract\_prices.contract\_comercial\_type\_id, public.hubspot\_contract\_prices. link\_al\_admin, public.hubspot\_contract\_prices.link\_al\_site FROM public.hubspot\_contract\_prices ORDER BY Company ID DESC LIMIT %(param\_1)s] [매개변수: {'param\_1': 50}] (이 오류의 배경: https://sqlalche.me/e/14/f405)다음은 MySQL에서 발생한 또 다른 오류입니다: (pymysql.err.ProgrammingError) (1064, "SQL 구문에 오류가 있습니다. 사용 중인 MySQL 서버 버전에 해당하는 설명서에서 2줄의 'ID DESC \n LIMIT 50' 근처에 사용할 올바른 구문을 확인하십시오.") [SQL: SELECT vw\_zap\_accredible\_pearson\_pro9.`Event ID`, vw\_zap\_accredible\_pearson\_pro9.`Zoho ID`, vw\_zap\_accredible\_pearson\_pro9.`파트너 이름`, vw\_zap\_accredible\_pearson\_pro9. 파트너 코드`, vw\_zap\_accredible\_pearson\_pro9.`학생 유형`, vw\_zap\_accredible\_pearson\_pro9.`인증서에 표시할 이름`, vw\_zap\_accredible\_pearson\_pro9.`인증서 그룹 ID`, vw\_zap\_accredible\_pearson\_pro9. `인증 번호`, vw\_zap\_accredible\_pearson\_pro9.`시험 시리즈`, vw\_zap\_accredible\_pearson\_pro9.`코스 이름`, vw\_zap\_accredible\_pearson\_pro9.`이메일`, vw\_zap\_accredible\_pearson\_pro9. `성`, vw\_zap\_accredible\_pearson\_pro9.`성`, vw\_zap\_accredible\_pearson\_pro9.`수정된 시간`, vw\_zap\_accredible\_pearson\_pro9. `코스 버전`, vw\_zap\_accredible\_pearson\_pro9.`시험 날짜`, vw\_zap\_accredible\_pearson\_pro9. Pearson ID`, vw\_zap\_accredible\_pearson\_pro9.`Grade`, vw\_zap\_accredible\_pearson\_pro9.`Total Exam Score`, vw\_zap\_accredible\_pearson\_pro9. `Result Exam A`, vw\_zap\_accredible\_pearson\_pro9.`Result Exam B`, vw\_zap\_accredible\_pearson\_pro9. `Result Exam C`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 1`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 2`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 3`, vw\_zap\_accredible\_pearson\_pro9. `Result Module 4`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 5`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 6`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 7`, vw\_zap\_accredible\_pearson\_pro9. `Result Module 8`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 9`, vw\_zap\_accredible\_pearson\_pro9.`Result Module 10` FROM vw\_zap\_accredible\_pearson\_pro9 ORDER BY Event ID DESC LIMIT %(param\_1)s] [매개변수: {'param\_1': 50}] (이 오류에 대한 배경: https://sqlalche.me/e/14/f405)그리고 SQL Server의 또 다른 오류입니다: get\_rows 중 예외 발생: (pyodbc.ProgrammingError) ('42000', "[42000] [FreeTDS][SQL Server]잘못된 구문이 '주소' 근처에 있습니다. (102) (SQLExecDirectW)") [SQL: SELECT TOP 50 dbo.[Zapier\_UK\_Mailchimp].[이메일 주소], dbo.[Zapier\_UK\_Mailchimp].[이름], dbo.[Zapier\_UK\_Mailchimp].[성], dbo.[Zapier\_UK\_Mailchimp].[브랜드], dbo.[Zapier\_UK\_Mailchimp].[부서], dbo. [Zapier\_UK\_Mailchimp].[Project], dbo.[Zapier\_UK\_Mailchimp].[Location], dbo.[Zapier\_UK\_Mailchimp].[Tags] FROM dbo.[Zapier\_UK\_Mailchimp] ORDER BY 이메일 주소 DESC] (이 오류의 배경: https://sqlalche.me/e/14/f405)모두 ORDER BY를 사용하여 선택된 것을 알 수 있습니다.