我试图在Python中使用SQL从JSON字符串中提取数据。我出错了
IndexError: tuple index out of range
下面是我正在尝试的示例查询
dwh_cursor.execute(sql.SQL("""SELECT a.id, a.name,B.setup as setup,
CASE WHEN (setup::JSON -> 'refcol')::TEXT = '{}' THEN 'data_missing'
ELSE 'data_correct' END AS ColumnMapping
FROM sales a join details b on a.sale_id = b.id
and a.name = {}""").format(sql.Literal(name)))
如果排除从JSON提取数据的最后一个表达式,则上述查询运行良好。只有在包含这个JSON提取列(col name:ColumnMapping)时才会出现错误。有谁能给我指点一下怎么解决这个问题。你知道吗
我用的是红移数据库。谢谢
如果只想格式化后面出现的
{}
,请用'{{}}'
转义第一个。你知道吗相关问题 更多 >
编程相关推荐