R
Railway•2y ago
inotmad

PostgreSQL not inserting data

So i have a bot that inserts data about files to a db that are uploaded to backblaze through it. I use postgre to keep track. im using psycopg2, and using the simple query:
CURSOR.execute('INSERT INTO lfs (file_id, file_name, user_id) VALUES (%s, %s, %s)', (file.id, ufile.filename, interaction.user.id))
CURSOR.execute('INSERT INTO lfs (file_id, file_name, user_id) VALUES (%s, %s, %s)', (file.id, ufile.filename, interaction.user.id))
This should be correct according to the psycopg2 docs. When i run the command, all goes well. The file is uploaded, the link for the file is returned, and no errors are printed. However when i check the table its empty? I tried running the query on railway, in the little tab for it, and it ran with no errors. What is interesting though is that the ID, which is a serial autoincrement field, was 3, meaning something was caught by the db, but the table was still empty. nothing was ever in the table. Im scratching my head at this. Project ID: 45ce4783-9560-4cd6-9fe7-8982bd5ab434
Solution:
by not being silly and commiting ur changes to sql
Jump to solution
6 Replies
Percy
Percy•2y ago
Project ID: 45ce4783-9560-4cd6-9fe7-8982bd5ab434
inotmad
inotmadOP•2y ago
oh forgot to add that when i ran the query on railways tab, it did insert it into the table thats how i saw the serial ID and stuff but before that i never caught anything checked the logs and found this:
2023-05-30 11:27:51.723 UTC [430] STATEMENT: INSERT INTO lfs (file_id, file_name, user_id) VALUES ('4_ze0dd563a2817669b8786051c_f115767d9eeeb5dc9_d20230530_m112751_c005_v0501003_t0054_u01685446071405', 'the-collective-knowledge-of-humanity-copy.py', 948491832608825415)
2023-05-30 11:31:27.347 UTC [430] LOG: could not receive data from client: Connection reset by peer
2023-05-30 11:27:51.723 UTC [430] STATEMENT: INSERT INTO lfs (file_id, file_name, user_id) VALUES ('4_ze0dd563a2817669b8786051c_f115767d9eeeb5dc9_d20230530_m112751_c005_v0501003_t0054_u01685446071405', 'the-collective-knowledge-of-humanity-copy.py', 948491832608825415)
2023-05-30 11:31:27.347 UTC [430] LOG: could not receive data from client: Connection reset by peer
but i still dont understand how do i mark as solved
luna
luna•2y ago
I'd also suggest posting how you fixed it so others can find it. 🙂
Solution
inotmad
inotmad•2y ago
by not being silly and commiting ur changes to sql
inotmad
inotmadOP•2y ago
CURSOR.connection.commit() if you use psycopg2. lol
Want results from more Discord servers?
Add your server