cbjessup / prettytable

Automatically exported from code.google.com/p/prettytable
Other
0 stars 0 forks source link

Field names must (not) be unique! #39

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
By design, PrettyTables forbids duplicate field names. But this very case 
naturally occurs in any table returned by an unfiltered cross product SQL 
request, e.g.:

    cursor = c.execute("SELECT * FROM foobar A, foobar B")
    t = prettytable.from_db_cursor(cursor)

Can you add an option to override the check for uniqueness?

Thanks!

Original issue reported on code.google.com by aristide.grange on 8 Oct 2013 at 7:57

GoogleCodeExporter commented 8 years ago
Hi there.

Removing the uniqueness requirement would be a fairly major undertaking, I'm 
afraid.  It's not a simple matter of overriding a check which is only there 
because I thought it was a good idea.  The underlying implementation is based 
entirely around dictionaries which have field names as keys, make duplication 
in possible.  So the change would require not only disabling the check, but a 
deep architectural change as well. :/

That's not to say I'll never do it.  It seemed like a good idea at the time, 
and surprisingly yours is the first complaint I've received about it in several 
years of PrettyTable being moderately popular.  But not that you do point it 
out, I can't convince myself that duplicate field names are NEVER a valid thing 
for a table to have.  So maybe I'll strive to remove that limitation one day, 
but I'm afraid it won't be anytime soon (such as the next release, which is 
hopefully only about a week away).

I suppose for the specific case of DB cursor results, I could modify 
from_db_cursor to automatically change ["foobar", "foobar", "foobar"] to 
["foobar (1)", "foobar (2)", "foobar (3)"] or something like that.  Maybe it's 
not pretty, but at least it stops the from_db_cursor function from completely 
breaking in a perfectly legitimate situation.

Original comment by luke@maurits.id.au on 8 Oct 2013 at 11:11