Click here to Skip to main content
14,333,745 members
Rate this:
Please Sign up or sign in to vote.
See more:
Writing the Nested Dictionaries in SQL Table. Code is getting written.

Since I'm dealing with nested dictionaries. So Main Dicionary (User_ID value) is getting writted one row and other Nested Dictionary values are getting written in another row..

I want to write all the values in the single row.

Let me know any suggestions to write the values in single row.

Code - Output( Userdefined Values)
('1101', {'Name': 'Test_User', 'Age': Test_Age, 'Occupation': 'Test_Occupation'})

I want to write all these nested dictionary values in the single row in SQL table.

SQL Output (For Example)
User_ID  User_name    User_Age    User_Occupation


         Test_User    Test_Age    Test_Occupation

Thanks for your time in Advance !!

What I have tried:

Part of code use to write the values into SQL Table :

for k,v in user_details.items():
            user_col = k
            cursor.execute('INSERT INTO Details (User_ID) VALUES ("%s")' % (user_col))

            cols = v.keys()
            vals = v.values()

            sql = "INSERT INTO Details ({}) VALUES ({})".format(
            ', '.join(cols),
            ', '.join(['%s'] * len(cols)));

            cursor.execute(sql, list(vals))
Kornfeld Eliyahu Peter 10-Oct-19 11:00am
How many nested directories do you have?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100