0

Hello i am new in python and im trying to learn basic things, right now i have made a query that gets chat_ID from database and i want to insert all the results inside an array but i cant make the values enter inside the array, this is the code i have done until now:

 query = "SELECT `chatid` FROM `chats`"
        cursor = await self.db.execute(query)
        record = await cursor.fetchall() 
        
        for row in record:
        chats_id = [row] #the array

I want the result to be

chats_id = ["1","2","3","4"];
5
  • list(row) should work Commented Mar 10, 2023 at 18:39
  • how do i make that chats_id = list(row) ? Commented Mar 10, 2023 at 18:43
  • Try looking at Return SQL result from function as array. Commented Mar 10, 2023 at 18:44
  • Depends. What are you trying to accomplish with chats_id ? If you gonna work row by row each loop iteration, then it's exactly what you suggested: ` chats_id = list(row) ` . Commented Mar 10, 2023 at 19:07
  • i need to fill the array thats it so if i make print(chats_id) to get ["1"], ["2"]... Commented Mar 10, 2023 at 19:08

0

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.