1

I'm getting this error message

 cursor.execute(query, variables)
psycopg2.errors.SyntaxError: syntax error at end of input

My code

data = {
 'country': data['country'][x],
 'year': data['year'][x].astype(float),
 'month': data['month'][x].astype(float)
}
db_connection.execute(
 f"""
 INSERT INTO my_table (country, year, month) VALUES (%(country)s, %(year)s, %(month)s) ON CONFLICT (country, year, month)
 """,
 data,
)
SebDieBln
3,4891 gold badge12 silver badges25 bronze badges
asked Dec 2, 2022 at 23:31

1 Answer 1

2

You're missing a conflict_action in your sql statement. See https://www.postgresql.org/docs/current/sql-insert.html#:~:text=ON%20CONFLICT%20DO%20NOTHING%20simply,can%20perform%20unique%20index%20inference. for details.

EG You might want ON CONFLICT (country, year, month) DO NOTHING

answered Dec 2, 2022 at 23:35
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.