Python Forum
Sequential number for rows retrieved and storing the Primary UKey to the line number - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Sequential number for rows retrieved and storing the Primary UKey to the line number (/thread-40582.html)



Sequential number for rows retrieved and storing the Primary UKey to the line number - GYKR - Aug-22-2023

Hi Forum,

My first post and also very new to Python. I need some help, please!

At the moment, when I retrieve the data from my table, it displays as below.

-------- -------- -------- --------- --
JOHN SMITH K8AC DEFAULT
DAVID SMITH C2TT DEFAULT
KEVIN HART AC2D ADMIN
JASON STATHAM T13T SUPERUSER
-------- -------- -------- --------- --

I am hoping to assign a line number to each row and at the same time stores the Primary UKey value to the line number, something like below

-------- -------- -------- --------- --
L1 JOHN SMITH K8AC DEFAULT
L2 DAVID SMITH C2TT DEFAULT
L3 KEVIN HART AC2D ADMIN
L4 JASON STATHAM T13T SUPERUSER
-------- -------- -------- --------- --

So that on the subsequent coding, I can simply retrieve the line number and edit that record rather than having to type the UKey value to identify the record I want to edit or delete. Thank you for the help!


RE: Sequential number for rows retrieved and storing the Primary UKey to the line number - menator01 - Aug-22-2023

What have you tried? How is the data stored. You will need to show your code for getting help.


RE: Sequential number for rows retrieved and storing the Primary UKey to the line number - GYKR - Aug-22-2023

(Aug-22-2023, 10:01 AM)menator01 Wrote: What have you tried? How is the data stored. You will need to show your code for getting help.

Thank you. Currently, data is stored in the Postgres database

elif usermenuoption == 3:
cur = conn.cursor()
cur.execute("SELECT * FROM python_test")
records = cur.fetchall()
print(tabulate(records))
print("\nALL RECORDS DISPLAYED.")