reversed order of db notices
Submitted by: marko kreen
when one statement issues several notices,
they appear in reversed order in .notices list. the reason is that they are prepended to temporary singly linked list which is later walked sequentially.
fix would be to append them to the singly linked list.
Comments and changes to this ticket
- State changed from new to open
You are right, and using conn.notifies.pop(0) (or insert(0) when adding items) is inefficient. Probably we should use collections.deque and appendleft() on our side so that pop() on the client side would work as expected.
By the way there is a similar problem in conn.notices, which is a list whose max length is clipped to avoid unbounded growth (a problem we had with excessive warnings before we starting respecting the standard_conforming_strings setting).
The problem is as usual with backward compatibility as deque doesn't support all the list interface (e.g. slicing, don't know what else). I don't expect to break much code though, and the gain would be huge.
Considering the notices are mostly debugging aid, I would not worry about efficiency too much.
But the reordering problem makes it hard to do even debugging, which is bad.
Note I was talking about this (temp) list:
struct connectionObject_notice *notice_pending;
not the Python array.
Uhm, I mixed notices and notifies: I think they both have the same efficiency problem.
notice_pendingcan definitely be fixed, thank you for the report. I agree the notices in this example should be made available in the opposite order in the notices list.
In : cur.execute("select 'a\\a';\nselect 'b\\b'") In : print '\n'.join(cnn.notices) WARNING: nonstandard use of escape in a string literal LINE 2: select 'b\b' ^ HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. WARNING: nonstandard use of escape in a string literal LINE 1: select 'a\a'; ^ HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.