Python 使用psycopg2为jsonb查询创建字符串

Python 使用psycopg2为jsonb查询创建字符串,python,string,psycopg2,psql,jsonb,Python,String,Psycopg2,Psql,Jsonb,我对数据库中的works有以下查询 SELECT count(*) as count FROM data WHERE name ='user' AND dt > date_trunc('month', current_timestamp) AND submited_jsonb @> '{"Type":["New"]}' GROUP BY mage, date_trunc('day', dt) 现在,在我的python版本中,我必须只传递名称 query =

我对数据库中的works有以下查询

SELECT count(*) as count
FROM data
WHERE name ='user' AND
      dt > date_trunc('month', current_timestamp) AND 
      submited_jsonb @> '{"Type":["New"]}'
GROUP BY mage, date_trunc('day', dt)
现在,在我的python版本中,我必须只传递名称

query = """SELECT count(*) as count
           FROM data
           WHERE name ='{0}' AND
                 dt > date_trunc('month', current_timestamp) AND 
                 submited_jsonb @> '{"Type":["New"]}'
           GROUP BY mage, date_trunc('day', dt)""".format(user)
但是上面的字符串有以下错误

ERROR:root:An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line string', (1, 12))
我已将错误减少到以下行 “{”类型“:[“新”]}”为字符串形式

我该怎么办?

您使用的是
“..”.format()
,因此您应该加倍文本
{}
以转义它们

...
submited_jsonb @> '{{"Type":["New"]}}'
...