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

  • Home
  • SEARCH
  • 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 8490757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:13:08+00:00 2026-06-10T22:13:08+00:00

I have a python dict like this: my_dict = {‘find’: [‘http://time.com’, ‘http://find.com’], ‘time’: [‘http://any.com’,

  • 0

I have a python dict like this:

my_dict = {'find': ['http://time.com', 'http://find.com'], 'time': ['http://any.com', 'http://www.tim.com', 'http://mine.in']...}

I want to insert keys and values of dictionary my_dict in two different columns of a mysql table. The columns names are term and urls respectively. I have three columns for now: id, term, urls and I want to insert each keys and values pairs in different rows.

I want to store the links in urls as seperated by commas. The website links in the values of my_dict must be stored seperated by commas like http://time.com, http://mine.com.
I tried to insert in the following manner

for i in my_dict.items():   
    keys = i[0]
    values = i[1]
    sql = """INSERT INTO index_table (term, urls) VALUES (%s, %s)"""
    cursor.execute(sql, (keys, values))

But it shows the following error:

(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 '))' at line 1")
  • 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-06-10T22:13:09+00:00Added an answer on June 10, 2026 at 10:13 pm

    Your values in this instance are lists which you are attempting to pass to the SQL query and that is causing you issues.

    If you want a separate record for each url in the values section (assuming you are going to always have a list for the values portion)

    for i in my_dict.items():
        term = i[0]
        for url in i[1]:
            sql = """INSERT INTO index_table (term, urls) VALUES (%s, %s)"""
            cursor.execute(sql, (term, url))
    

    Or if you want to store the urls together in one record, you would need to pickle the list or convert to a format like json. Would require you to handle the data appropriately when pulling the data out from the database

    import json
    for i in my_dict.items():
        term = i[0]
        urls = json.dumps(i[1])
        sql = """INSERT INTO index_table (term, urls) VALUES (%s, %s)"""
        cursor.execute(sql, (term, urls))
    

    To store the urls in comma separated format instead;

    for i in my_dict.items():
        term = i[0]
        urls = ', '.join(i[1])
        sql = """INSERT INTO index_table (term, urls) VALUES (%s, %s)"""
        cursor.execute(sql, (term, urls))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: award_dict = { "url": "http://facebook.com", "imageurl": "http://farm4.static.flickr.com/3431/3939267074_feb9eb19b1_o.png", "count": 1, }
I have a dict of configuration variables that looks something like this: self.config =
I have a python dict and I'd like to silently remove either None and
Say I have a string that looks like this: str = The &yquick &cbrown
I have a custom file format for graphs which looks like this: node1.link1 :
Possible Duplicate: python dict.add_by_value(dict_2) ? My input is two dictionaries that have string keys
I have a lot of archive data in python dict format that I am
Let's say I have a class like this: class Test(object): prop = property(lambda self:
I have a list of dicts, something like this: test_data = [ { 'offset':0,
I thought this must already have been answered, but I couldn't find anything on

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.