Sqlalchemy query data, sort according to the data in the field (Chinese) to Pinyin (ascending order)

1.sqlalchemy query data, sort according to the data in the field (Chinese) to Pinyin (ascending order)
2. It is known that there are func.convert and sql.func.CONVERT methods in sqlalchemy, and the import method is

.
from sqlalchemy import func
from sqlalchemy import sql

here"s how I implement it

self.db.query(Table).order_by(
            sql.func.CONVERT(sql.literal_column("VARCHAR(8)"), 
            Table.department_name, sql.literal_column("8"))).all()

result hint:
ProgrammingError: (_ mysql_exceptions.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 "VARCHAR (8), Table.department_name, 8)

I don"t know how to implement it.


there is a referenced link https://stackoverflow.com/que., but it does not solve the problem


self.db.query(Table).order_by(
            sql.func.CONVERT(sql.literal_column('department_name as gbk'))
            ).all()

that should do it. Sql.literal_column is essentially a method that passes arbitrary code into a method that goes back and forth to func.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be63fb-30f5d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be63fb-30f5d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?