update postgre going wrong

Asked

Viewed 34 times

0

Follows the code:

def update_table(file_name, id, column1, column2):
    conn = connect()
    c = conn.cursor()

    today = str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%Y/%m/%d/'))

    query = f"""UPDATE "IMPRESSAO" SET "{column1}" = %s, "{column2}" = %s
                       WHERE "NUM_IMPRESSAO" LIKE '%{id}';"""
    print(query, "\n")
    data = (file_name, today)

    try:
        c.execute(query, data)
        conn.commit()
        count = c.rowcount
        print(f"\033[1;32;m {count} Record(s) inserted successfully")

    except Exception as e:
        print(f"\033[1;31;m update_table error: {e}")

    finally:
        if conn is not None:
            conn.close()

What’s wrong with it? Presents the following error:

tuple index out of range

I’m new to postgre, so I may have done a lot of wrong... Thanks in advance.

  • And what is the print(query, "n") output? Nothing is missing from the previous assignment?

  • exit this: UPDATE "IMPRESSAO" SET "BINARY" = %s, "DATA_ENVIO_BINARY" = %s WHERE "NUM_IMPRESSAO" LIKE '%08918';

  • Try trading '%Y/%m/%d/' for '%Y-%m-%d' (date in ISO format).

  • This message seems to refer to python. On the output in the terminal the error message does not indicate which line is generating the error? It would be interesting to add more information to the question.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.