0

I am trying to insert data into a postgres table using variables. Having looked at other answers on this topic it seemed pretty straightforward, however I am getting a syntax error from python before I even get a chance to insert it into the database

The execute statement I am using:

cur.execute("""INSERT INTO "public"."catalogue_product" ("id","structure","upc","title","slug","description","rating","date_created","date_updated","is_discountable","parent_id","product_class_id","collection_id","multiplier","dimension","feat1","feat10","feat2","feat3","feat4","feat5","feat6","feat7","feat8","feat9","image_url","price","short_name","sku") VALUES (nextval'catalogue_product_id_seq'::regclass),'standalone',NULL,%s,'noslug',%s,NULL,current_timestamp,current_timestamp,TRUE,NULL,NULL,NULL,'2.2',%s,'','','','','','','','','','',%s,%s,%s,%s)""", (name, desc, dimension, imageurl, price, shortname, sku))

All parenthesis and quotes match as they should as far as I can see.

What could be causing this?

edit: As per an answer below, I switched to using tripple quotes (and edited the code above to reflect) which does seem to help, but I still get an error:

psycopg2.ProgrammingError: syntax error at or near "'standalone'"
LINE 1: ...ES (nextval'catalogue_product_id_seq'::regclass), 'standalon...

1 Answer 1

1

You have an extra ) that closes the VALUES list too early:

... ::regclass),'standalone' ...
          THIS^
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, thank you! Not sure how I missed something so obvious.

Your Answer

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.