In psycopg2, if I have a table:
+------+-----+-------+
| name | age | color |
+------+-----+-------+
| Bob | 25 | red |
| Bill | 50 | blue |
| Jane | 45 | black |
+------+-----+-------+
If I do cursor.execute("SELECT * FROM mySchema.this_table LIMIT 1")
then I check if color exists with:
colnames = [desc[0] for desc in cursor.description]
then search colnames for 'color'
then I think I get the row with:
myrow = importCursor.fetchone()
but how do I get the 'color' value of that row?
I tried color = importCursor.fetchone()['color']
but that doesn't work.
How do I get the color value of the row returned by that SELECT statement? I don't know how many columns there are in the table, or if the 'color' column will always be column #3 I have to do this for a bunch of columns in this table (check if exists, if does, return column value of row) so an efficient way is best!
cursor.execute('select color from myschema.this_table limit 1'),color = cursor.fetchall()