有一段代码,根据模块中包含的数据类型,写入不同的区间。但是在写入文件名的时候会出现一个问题,因为它们有“.”这样的值,一个记录文件的例子:
__Release_Notes/Q3.2/Poy/3154__Data_1
但在一个名为:
__Release_Notes/Q3.1/C394
他抱怨
psycopg2.errors.SyntaxError: syntax error at or near ".1"
LINE 4: ... (__Release_Notes/Q3.1/
代码本身看起来像这样
# SQL-запрос для создания новой таблицы
def create_table(time, cursor, count_time):
create_table_query = f'''CREATE TABLE IF NOT EXISTS {time}
(
metada TEXT PRIMARY KEY NOT NULL,
{count_time} INT
); '''
cursor.execute(create_table_query)
# Выполнение команды: это создает новую таблицу
def inster_into_table_one_day(cursor, Changedata, time):
#dfirst need del
ID = 1
for ticket, day in Changedata.items():
if ticket == 'Merge_or_Fix':
continue
ID += 1
insert_table_query = f'''INSERT INTO {time}
(metada, one_day)
VALUES
('{ticket}', {day})
; '''
cursor.execute(insert_table_query)
解决方案是隔离数据,
'否则"可能会导致数据类型错误,所以我将所有内容更改为text