Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何通过名称而不是位置访问列?_Sql_Sqlite_Select_Tuples - Fatal编程技术网

Sql 如何通过名称而不是位置访问列?

Sql 如何通过名称而不是位置访问列?,sql,sqlite,select,tuples,Sql,Sqlite,Select,Tuples,我刚刚尝试了我的第一个sqlite select语句,得到了一个结果(元组上的迭代器)。因此,换句话说,每一行都由一个元组表示,我可以像这样访问该行单元格中的值:r[7]或r[3](从第7列或第3列获取值)。但我不想通过它们的位置而是通过它们的名字来访问这些列。比如说,我想知道user\u name列中的值。怎么做?我找到了我问题的答案: cursor.execute("PRAGMA table_info(tablename)") print cursor.fetchall()

我刚刚尝试了我的第一个sqlite select语句,得到了一个结果(元组上的迭代器)。因此,换句话说,每一行都由一个元组表示,我可以像这样访问该行单元格中的值:
r[7]
r[3]
(从第7列或第3列获取值)。但我不想通过它们的位置而是通过它们的名字来访问这些列。比如说,我想知道
user\u name
列中的值。怎么做?

我找到了我问题的答案:

cursor.execute("PRAGMA table_info(tablename)")
print cursor.fetchall()