-3
postgreSQL_select_Query = "select Query"

        cur.execute(postgreSQL_select_Query)

        records = cur.fetchall() 
        print("Selecting rows ",records)
        print("Print each row and it's columns values")
        for row in records:
             print(row)

in the above code print row is given below.

('1970-01-01', '1')
('2019-01-01', '2')
('2019-01-12', '3')
('2019-01-19', '2')
('2019-02-16', '1')
('2019-02-19', '1')
('2019-02-22', '1')
('2019-02-24', '1')
('2019-02-25', '1')
('2019-02-26', '1')
('2019-03-02', '1')
('2019-03-05', '1')
('2019-03-07', '1')
('2019-03-08', '1')
('2019-03-10', '1')
('2019-03-13', '2')
('2019-03-16', '1')

How to convert above result to list of list in python The assumed result is list=[['1970-01-01', '1'],['1970-01-01', '1']]

Bibin
  • 492
  • 5
  • 11

1 Answers1

-1

list comprehension is what i am going to use

postgreSQL_select_Query = "select Query"
cur.execute(postgreSQL_select_Query)
records = cur.fetchall() 
output = [list(row) for row in records]

output is what you need here i guess

Shrey
  • 1,242
  • 1
  • 13
  • 27