1

I have a simple 2 column table with the fields id and entry.

I want to select only the entries:

SELECT entry FROM table

However this query generates a multi dimensional array. I need to generate a simple, single-dimensional array. I know I could possibly do this after in my Phyhon code but the database is very large (100,000+ columns) and I'd like to not have to go through this extra step before I can exploit my data.

asked Dec 21, 2013 at 8:22

1 Answer 1

1

Unpack the result as follow:

cursor.execute('SELECT entry FROM table')
rows = [entry for entry, in cursor.fetchall()]
# ^

>>> rows = [('entry1',), ('entry2',), ('entry3',)]
>>> rows
[('entry1',), ('entry2',), ('entry3',)]
>>> rows = [entry for entry, in rows]
>>> rows
['entry1', 'entry2', 'entry3']
answered Dec 21, 2013 at 8:24
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.