-
-
Notifications
You must be signed in to change notification settings - Fork 505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting OID of the table from which the given column was fetched #661
Comments
I can think of two ways to add such kind of information:
I better like (2) because being an explicit call it will allow for future expansion like adding data that requires a roundtrip to the backend without any extra overhead if not called. If you want to send a patch remember to also include tests and documentation. :) |
Makes sense, molte grazie. We'll go for second option. Describe method will return a tuple (or namedtuple if available) containing (PQftable, PQftablecol) - parent table OID and column number within parent table. Is that ok? |
I think it is better if the content of the tuple is an object , not another tuple. Explicit naming is better that positional. Something along the lines of:
|
Well, this is "describe" for the whole resultset. But in previous round, we've agreed (to keep things simple) that describe method will return info just for one specific column. Does it mean, that result for one column should be dict too? My boss would be pleased, he doesn't like tuples at all. On the other hand dicts can't be unpacked. Some says a named tuple should be used in this case. What's your preference? |
Yes, sorry - I was still thinking about the |
Oh, I thought I had added something to this conversation yesterday. I lost it somehow :\ ok... The conversation is getting confused, let's make some order :)
@xpuu: the info you want to add come from functions such as What we should do is:
this way eventual code unpacking the description with idioms like Notice that inheriting from a nameduple is not difficult in Python itself: class ColumnDescription(namedtuple('ColumnDescription', 'name type_code display_size internal_size precision scale null_ok')):
def __init__(self, *args):
self.table = None
cd = ColumnDescription(*range(7))
cd.table = 'asdf'
>>> cd
ColumnDescription(name=0, type_code=1, display_size=2, internal_size=3, precision=4, scale=5, null_ok=6)
>>> cd.name
0
>>> cd.table
'asdf' never done it in C but it should be doable (also the above Python representation is not necessarily right because that object is immutable so it should actually implement |
@dvarrazzo very good summary but I don't agree with your proposed solution because:
That's why I proposed a new method |
@fogzot about newer versions on the api, I don't hold my breath. The api is firmly rooted in the '90s, it doesn't mention 1: unicode support, 2: python 3 changes, 3: asynchronous communications, and the last attempts of discussions on the dbsig ml orbited around... placeholders. All in all I don't see them dictating to add something mandatory as implement About your point 2: these functions in my understanding don't take a network trip. If they did I would prefer too to have them exposed as functions instead of smuggled as attributes. But in my understanding the attribute requested are on the result objects already on the client side. For instance, we already use
...other functions work on the result records, or on prepared statements, so I guess the buck stops here. I'd say the results of all the functions with interface (PGresult *, int) are good candidates to be exposed as attributes of
to which we can add
Adding these attribute has no overhead: the functions only use the client-side result. They are ordered for usefulness (for me) and we may implement all the 5 or only some of them. |
Added |
Hey @dvarrazzo, Few of our users get the table_oid as negative value. It mostly happens with large DB's with lot many tables and columns. Thanks for the great work :) |
@adityatoshniwal does it mean that if you |
@adityatoshniwal you are right: the |
Our team recently switched from PHP to Python3. In PHP we were in some cases using function pg_field_table, which basically calls to PQftable returning the OID of the parent table (or 0 for formula/function).
We think, that getting this kind of information might be useful for other developers too. Because it's already present in libpq result attributes anyway, it's also cheap to obtain. The easiest and most logical (for us) seemed to add table OID as a new item to cursor.description tuple. We made a few lines patch and succesfully tested it in real life.
Do you think, that providing table OID (in whatever way you decide is correct), could make it's way to official release? It'd makes things much easier for us. And if so, how can we help to let this happen?
The text was updated successfully, but these errors were encountered: