Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6529951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:41:52+00:00 2026-05-25T09:41:52+00:00

I have a problem with MySQL and Python’s MySQLdb when I try to INSERT

  • 0

I have a problem with MySQL and Python’s MySQLdb when I try to INSERT more than one variable.

I have a table wordurl with three fields. The first one is an auto_increment ID, second and third should hold the values. Second and third fields are named word_id and url_id.

This is the code.

cursor.execute("INSERT INTO wordurl (word_id, url_id) VALUES (%s, %s)", (word_temp_id, url_temp_id))

When I try to INSERT only one value the code works, two not.

Error message:

(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '),), (('2',),))' at line 1")

I also tried it with tripple ticks around the statement, the variables with and without bracket, without the field names and with the first id field included. I also tried with C-style-printf-stuff % (which isn’t clever!). Nothing worked.

And you, glorious people on stackoverflow, you are my last hope 🙂

MySQL-Server is 5.5.9 on FreeBSD 8.2. Python version is 2.7:82508 on OSX Lion

Thanks in advance!

Steffen

UPDATE: I use cursor.fetchall() and cursor.fetchone() to get the IDs. Maybe this information is important.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:41:52+00:00Added an answer on May 25, 2026 at 9:41 am

    Regarding your update:

    AFAIK:
    fetchall() returns a tuple with tuples inside. Those tuples inside are what you would get from fetchone(). You can image it like

    fetchall() = (fetchone(), fetchtwo(), ...)
    

    And fetchone also returns a tuple which has the actual variable values. This is why you can’t simply insert the return value of fetchall().

    Just to clarify: the insert statement you pasted, look like this when you fill in the value for max_price:

    c.execute("""SELECT spam, eggs, sausage FROM breakfast WHERE price < %s""", (5,))
    

    so the first %s is replaced with the first element of the tuple (5). Your insert statement looks like this:

    cursor.execute("INSERT INTO wordurl (word_id, url_id) VALUES (%s, %s)", (((233L,),), ((3L,),)))
    

    I can’t make it more clear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I have problem with my MySQL query: include '../inc/mysql_config.php'; $sql=INSERT INTO ordrar (id, order,
I have a problem using the MySQLdb library. I'm trying to insert values into
I have MYSQL & MYSQLdb installed with Python 2.6 & Django 1.2.3. I can
So My problem is this, I have a query that uses Mysql User-defined variable
I am currently trying to solve this problem in MySQL. I have MySQLdb installed.
I have a mysql problem, my query looks as follows but not complete SELECT
I have problem with creating a simple MySQL trigger in C#. I'm using StringBuilder
I have a problem with the MySQL root user in My MySQL setup, and
I have problem with setting proper charset on my jsf pages. I use MySql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.