简体   繁体   English

使用字典中的值作为Sqlite查询中的列标题

[英]Use value from dictionary as column header in Sqlite query

I have an Sqlite database that I need to query from python. 我有一个需要从python查询的Sqlite数据库。

The database only has two columns, "key" and "Value", and the value column contains a dictionary with multiple values. 数据库只有两列,即“键”和“值”,并且值列包含具有多个值的字典。 What I want to do is create a query to use some of those known dictionary keys as column headers, and the corresponding data under that column. 我想做的是创建一个查询,以使用其中一些已知的字典键作为列标题以及该列下的相应数据。

Is it possible to do that all in a query, or will I have to process the dictionary in python afterwards? 是否有可能在查询中完成所有操作,还是之后需要在python中处理字典?

Example data (values obviously have been changed) that I want to query. 我要查询的示例数据(显然值已更改)。

key                             |   Value
/auth/user_data/fb_me_user      | {"uid":"100008112345597","first_name":"Tim","last_name":"Robins","name":"Tim Robins","emails":["t.robins@gmail.com"]"}

There are lots of other key / value combinations, but this is one of the ones I am interested in. 还有许多其他键/值组合,但这是我感兴趣的组合之一。

I would like to query this to produce the following; 我想对此进行查询以产生以下内容;

UID              |  Name        |   Email
100008112345597  |  Tim Robins  |   t.robins@gmail.com

Is that possible just in a query? 仅在查询中可能吗?

Thanks 谢谢

after querying you get the value like below. 查询后,您将获得如下所示的值。 from them you can get 从他们那里你可以得到

value='''{"uid":"100008112345597","first_name":"Tim","last_name":"Robins","name":"Tim Robins","emails":["t.robins@gmail.com"]}'''

import ast
details=ast.literal_eval(value)
print details['uid'],details['name'],','.join(details['emails'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM