import psycopg2
connection = psycopg2.connect("********")
cur = connection.cursor()
list = []#By the way, I can't make this
cur.execute("SELECT ID FROM DB;")
list = cur
print(list)
It seems impossible to put it in directly
cur
What you can get with[(1),(2),(3)]
It is difficult to handle because tuple is included in the list. So I want to create a variable added as a string in the list
import psycopg2
connection = psycopg2.connect("********")
cur = connection.cursor()
list = []
cur.execute("SELECT ID FROM DB;")
for i in cur:
list.append(str(i[0]))
print(list)
This is easy to handle because it is created like `` `[1,2,3] ```
Recommended Posts