I am working on a Postgres viewer using Python. I need to convert all columns to text so I can display them in my GUI. I don't know how many columns there are per table or the names of them as this is supposed to be a generic viewer. Google got me this code:
SELECT t.*::text FROM table AS t;
However, this concatenates the row like this:
t
----------------|-------
(712,982,dfdfv)
What I need is this (with type text of course), just like a normal SELECT *
does:
id | vendor_id | vendor_barcode
----|-----------|---------------
712 | 982 | dfdfv
Edit1: I can't convert the datatypes in Python, because a None will become a 'None'.
Edit2: I need the column names from cursor.description(), so I can't use t.*::text.
Ok, so one solution offered by @Jon Clements is:
My final solution was:
Which converts blank strings to
''
and preservesNone
values. My code is actually more extensive, because it needs to create treeview columns and etc. Hopefully this helps out anyone coming here in the future.