我有一个名为id,name,salary的5列。在postgres DB中。
我正在获取列的所有值&存储到json文件中。 但我得到的问题是我无法存储值w.r.t键意味着列名是键。我想将值存储为列名作为键。
我尝试过:
curser.execute(select id,name,salary, dept from employee)
record = curser.fetchall()
这里的记录是列表的形式。 我想要下面这样的东西:
{
"id":"1"
"name":[{"first":"abc"},{"last":xyz}]
likewise others
}
but i am getting like:
{
1
[{"first":"abc"},{"last":xyz}]
}
有人可以看到问题。如果有任何其他澄清需要,请随时问我。谢谢提前
{
"guid": "9c36adc1-7fb5-4d5b-83b4-90356a46061a",
"name": "Angela Barton",
"is_active": true,
"company": "Magnafone",
"address": "178 Howard Place, Gulf, Washington, 702",
"registered": "2009-11-07T08:53:22 +08:00",
"latitude": 19.793713,
"longitude": 86.513373,
"tags": [
"enim",
"aliquip",
"qui"
]
}
But i need like:
{
details:{
"guid": "9c36adc1-7fb5-4d5b-83b4-90356a46061a",
"name": "Angela Barton",
"is_active": true,
"company": "Magnafone",
"address": "178 Howard Place, Gulf, Washington, 702",
"registered": "2009-11-07T08:53:22 +08:00",
"latitude": 19.793713,
"longitude": 86.513373}
"tags": [
"enim",
"aliquip",
"qui"
]
}
Here details is the columns.