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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -