Search code examples
pythonsqlcursorfetchallpresto

presto fetch data


I have a result like this from presto command:

  a| b| c  
 --+--+------
 1 | 3| 6 
 2 | 4| 5 

I know of cursor.fetchall() for all the data and cursor.fetchone() for a single row.

Now, I would like to get all the data from a particular column e.g. a [1, 2]

Is there a way to to this?


Solution

  • Saw something and modified it to solve the problem

    class reg(object):
     def __init__(self, cursor, row):
        for (attr, val) in zip((d[0] for d in cursor.description), row) :
            setattr(self, attr, val)
    

    and have a loop to get the columns

    for row in cursor.fetchall():
      r = reg(cursor, row)
      print r.a