MariaDB query from python code -
i'm writing python script connects mariadb server (v 10.1.12) , saves file results of queries. however, when sending following query:
sql = 'select * monitor_run_tracking entry in (select max(entry) ' \ 'from monitor_run_tracking run in ({0}) ' \ "and whenentered<'{1}' group run)".format( runstr, quality_date )
followed cursor.execute( sql )
, following error:
file "build/bdist.linux-x86_64/egg/mysqldb/cursors.py", line 174, in execute
file "build/bdist.linux-x86_64/egg/mysqldb/connections.py", line 36, in defaulterrorhandler _mysql_exceptions.programmingerror: (1064, "you have error in sql syntax; check manual corresponds mariadb server version right syntax use near ') , whenentered<'2020-01-01' group run)' @ line 1")
could explain me mistake is?
thanks!
you didn't close parenthesis around nested select. should be
select * monitor_run_tracking entry in ( select max(entry) monitor_run_tracking run in ({0}) , whenentered<'{1}') group run
or
select * monitor_run_tracking entry in ( select max(entry) monitor_run_tracking run in ({0}) , whenentered<'{1}' group run)
edit: other problem, you're grouping field you're not selecting. check out this question help.
Comments
Post a Comment