Search code examples
pythonmysqlpython-3.xmysql-connector-python

How to not unpack all returned from a query?


I have the following query (notice not a normal SELECT):

sql = "SHOW PROCEDURE STATUS WHERE Db <> 'sys' "

Problem this returns many fields, which I need only the first two, see full code:

sql = "SHOW PROCEDURE STATUS WHERE Db <> 'sys' "
self.cursor.execute(sql)
res = [(Db,Name) for(Db,Name,a,b,c,d,e,f,g,h,j) in self.cursor]

For this to not error out, I need to add all those a...j variables which I do nothing with.
How do I write this in a cleaner way?

I am using the connector supplied by Mysql/Oracle


Solution

  • Try:

    res = [(Db,Name) for(Db,Name,*_) in self.cursor]
    

    The * format in tuple unpacking represents "a "catch-all" name which will be assigned a list of all items not assigned to a "regular" name."

    References: