What I am up to is: I want to insert formatted values into a PostgreSQL Table which I created in Python.
What my code is doing: reading couple .txt files with many measurements which will be formatted and saved into one .txt file.
My code:
folder_path =(r"C:\Users\yokay\Desktop\bla")
values_re = re.compile(r'(\t\d+\t-?\d+,?\d*(\t-?\d+,?\d+){71})')
outF = open("MessungenTestTest.txt", "a")
for filename in glob.glob(os.path.join(folder_path, '*.txt')):
with open(filename) as lines:
for line in lines:
match = values_re.search(line)
if match:
values = match.group(0)
values = values[1:]
values = values.replace(',','.')
values = values.replace('\t',',')
outF.write(str(values)+"\n")
print(values)
insert_state = "INSERT INTO MessungenTest(MessungNr, FS22SI_1_CH_1_Sensor_1_CH_6_Crackmeter_Mikrometer, ...73 columns...) Values(?????)";
cur.execute(insert_state)
The(?????) in Values stands for I don't know what to put in. I tried with %s,%s, etc. but i get an Error:
ProgrammingError: FEHLER: Syntaxfehler bei »%« LINE 1: ...22SI_1_CH_8_Sensor_6_CH_77_Crackmeter_Mikrometer) VALUES(%s)
Everything works fine till i try to insert the values into the table.
If this helps: the column "MessungNr" have the Datatype integer, the other 73 columns have the datatype numeric(10,2).
Thank you for your time!